Hello everyone! I’m working on a site for a new client, and I’ve been taking my first steps with Custom Post Types. Right now, I have two Custom Post Types setup (Accessories and Business Products), as well as custom categories within each. Both post types have a custom category of Featured, which I’m using to display certain posts in a specific area.
I have an area on one page that I’d like to use to display those Featured posts, but I’m not sure of how I can query Featured posts from both Custom Post Types. The code below is what I would love to see work, but doesn’t, given the two following lines.
"accessories_cat" => "featured", "business-products_cat" => "featured",
<?php $query = new WP_Query( array( "post_type" => array("accessories","business-products"), "order" => "ASC", "orderby" => "rand", "accessories_cat" => "featured", "business-products_cat" => "featured", ) ); while ($query->have_posts()) : $query->the_post(); ?>
If I use only one line, it will only show posts from that category, as to be expected. Is there anyway I can specify one or more categories from different Custom Post Types, without having to specify which specific Custom Post Type the category is from?
- The topic ‘Querying Multiple CPT's and Categories’ is closed to new replies.