[wp-hackers] Get query variables and tags

Ade Walker photofantaisie at gmail.com
Wed Feb 4 00:52:39 GMT 2009


Thanks DD!

I was hoping to take a shortcut as get_query_var works fine. However,
WP_Query doesn't seem to accept tag= as a parameter (I was hoping I could
simply pass the $tag variable to WP_Query). I already have a main loop going
on in the same page and therefore I don't think I can use query_posts
either, which would have let me do this. I'll take a closer look at the
get_objects_in_terms and get_posts suggestions to see how to get this to
work.

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..
>


More information about the wp-hackers mailing list