[wp-hackers] Get query variables and tags

DD32 wordpress at dd32.id.au
Tue Feb 3 00:20:37 GMT 2009

In addition, If you want to use all the normal Template tags (such as
the_title(), the_permalink(), etc) you might want to create your own
loop: http://weblogtoolscollection.com/archives/2008/04/13/define-your-own-wordpress-loop-using-wp_query/

You basically do the same, But instead of ->query('showposts=5'); use
->query( array('post_in' => $objects, 'showposts' => <number of posts
you want>) );

I should've mentioned WP_Query defaults to 5 posts.. (Which get_posts
uses internally), you can set the post number to 0 to retrieve them

2009/2/3 DD32 <wordpress at dd32.id.au>:
> What i would do:
> $tag = get_query_var('tag');
> //Might need to convert 'MyTag' into a TermID here.. not sure
> $objects = get_objects_in_term('post_tag', $tag)
> $posts = get_posts( array('post_in' => $objects) );
> Or something similar.... You'll have to check the get_objects
> function.. and WP_Query for the correct usage of post_in..
> 2009/2/3 Ade Walker <photofantaisie at gmail.com>:
>> Hi all,
>> I would be very grateful to get a pointer or two for this, please.
>> I have a single post template with a sidebar which is to be populated with
>> links to other posts (from the same category). Each post has various tags
>> assigned to it. If the user clicks a tag, which are listed on the page using
>> the_tags(), I want the sidebar list of posts to only reflect posts which
>> have the same tag.
>> I was thinking that if I could access the query string and identify which
>> tag had been clicked, I could then run a wp_query to pull posts with the
>> same tag.
>> So, my questions are (1) how do I grab the query string to identify which
>> tag had been clicked, and (2) would I use get_the_tags() to filter the
>> results of the wp_query?
>> I have a feeling I'm either oversimplifying what is required - or
>> over-complicating it! So any pointers would be very gratefully received.
>> Thanks in advance.
>> Ade.
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list