Custom Query for Category and Tag
-
I’m pretty new to both WordPress and PHP, so I’d really appreciate any help. Overall, I’m disappointed with the confusing structure (and horrible search function) of WordPress, but I know that I will be able to find an answer to my question here.
I’m trying to cross-reference a post from Category A with a post from Category B. Both posts have been given Tag C, so for every post in Category A, I’m writing a custom query to pull the post from Category B with the same tag. (It’s a many-to-one relationship, where multiple posts in Category A correspond with the same post in Category B.) Unfortunately, I can’t seem to successfully write a query that calls a specific post from both a category AND a tag. Here’s the code I’m currently using:
$my_query = new WP_Query("cat=7&tag=$myVariable&showposts=1");
In theory, then, this should pull all posts from category 7 with the tag $myVariable. If I type in the tag name manually, it still doesn’t work. Strange thing is, I’ve tried looking at all posts with Tag C, and I only see the post from Category A, even though the post from Category B has the same tag. So, the problem here may be with the tagging, not with the query syntax.
Any help would be greatly appreciated!
- The topic ‘Custom Query for Category and Tag’ is closed to new replies.