[wp-hackers] Get query variables and tags

DD32 wordpress at dd32.id.au
Mon Feb 2 23:44:16 GMT 2009


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