Home › Forums › Back End › WordPress Post Queries › Re: WordPress Post Queries
Okay, so I have come unstuck on this query thing and need some help, please?
In my category.php file, I need to run a few queries (using WP_Query) in order to display the following:
* One post from the the current category that is tagged as “featured”
* Two posts from the current category that is tagged “hot”
* Two posts from the current category
So my questions are:
1. Can you use QP_Query to find articles tagged with a particular tag, but only from a particular category? i.e. Category = DVD and Tag = Featured?
2. Can you do the above for the currently viewed category? i.e. When browsing DVD, the category.php template is called, but I only want to show featured posts from that category…
All I have down thus far is:
< ?php $my_query = new WP_Query( array( 'category' => ‘my-category’ , ‘tag’ => ‘my-tag’, ‘posts_per_page’ => 1) ); ? >
< ?php while ( $my_query->have_posts() ) : $my_query->the_post(); ? >
< ?php endwhile; ? >
But that selects either the category or the tag, not both.
And then to get the current category, I tried:
< ?php $current_category = single_cat_title("", false); ? >
< ?php $my_query = new WP_Query( array( 'category' => ‘$current_category , ‘tag’ => ‘my-tag’, ‘posts_per_page’ => 1) ); ? >
< ?php while ( $my_query->have_posts() ) : $my_query->the_post(); ? >
< ?php endwhile; ? >
Which is a bit of a hack at best…
Any help would be appreciated. Thanks in advance.