[wp-hackers] Get query variables and tags

Ade Walker photofantaisie at gmail.com
Mon Feb 2 23:51:32 GMT 2009


Thanks so much! That's exactly the kind of thing I was looking for. I'll now
go and have a play and see if I can get it to work.
Thanks again.
Ade.

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