Querying Multiple CPT's and Categories (1 post)

  1. lawrencek
    Posted 3 years ago #

    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",
      $query = new WP_Query(
          "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?

Topic Closed

This topic has been closed to new replies.

About this Topic