Display Posts in Looper which are from Custom Post Type or Custom Taxonomy

I’ve got a CPT called Business Services and a custom taxonomy called Business Services. I want to display posts in my looper that are from the Business Services CPT or have been tagged with the Business Services taxonomy. I’ve tried creating multiple arrays for a var dump, but nothing seems to work.

This is my array

$query = array(
  'post_type'           => 'business_ser_dir_ltg',
  'post_status'         => 'publish',
  'ignore_sticky_posts' => 1,
  'posts_per_page'      => -1,
  'orderby'             => '{{dc:url:param key="orderby" fallback="rand"}}',
  'order'               => '{{dc:url:param key="order" fallback="dsc"}}',
  'offset'              => 0,
  'category_name'       => '{{dc:term:slug}}',
  'tax_query'           => array(
          'relation' => 'AND',
          array(
                'taxonomy' => 'secondary_listing_category',
                'field'    => 'slug',
                'terms'    => 'business-services',
                'operator' => 'IN',
          ),
      ),
  );

var_dump( http_build_query( $query ) );

This is query that was built, but does not work:
post_type=business_ser_dir_ltg&post_status=publish&ignore_sticky_posts=1&posts_per_page=-1&orderby={{dc:url:param key="orderby" fallback="rand"}}&order={{dc:url:param key="order" fallback="dsc"}}&offset=0&category_name={{dc:term:slug}}&tax_query%5Brelation%5D=AND&tax_query%5B0%5D%5Btaxonomy%5D=secondary_listing_category&tax_query%5B0%5D%5Bfield%5D=slug&tax_query%5B0%5D%5Bterms%5D=business-services&tax_query%5B0%5D%5Boperator%5D=IN

What do I need to change in my array to get the looper to display posts from my CPT and custom taxonomy?

Hey @OctoCog,

Thanks for writing in! Please explore by removing 'category_name' => '{{dc:term:slug}}', in your query argument and generate a new query string. If it does not help, we would love to inspect your looper. You can create a secure note in your next reply with the following info:
– Link to your site
– WP login URL
– WP username
– WP password
– WP Administrator Role
– Confirmation that we can access and make changes to your site

To know how to create a secure note, please check this out: How The Forum Works

image

Best Regards.

Hi @ruenel

Thank you for the recommendation, but it didn’t work. I tagged The Lobster Shanty under Eat, Drink, Stay the custom post type and tagged it ‘Business Services’.

I added a secure note. You can go ahead and access the site and make whatever changes are necessary.

Hey @OctoCog,

I have checked your custom post type. I am just confused because none of the Business Services listings has the business-services taxonomy assigned to it. You can either add the post types in an array

'post_type'  => array('business_ser_dir_ltg', 'eat_drink_dir_ltg', 'non_profits_dir_ltg', 'retail_dir_ltg', 'the_arts_dir_ltg'),

or completely change your query argument into just this one:

$query = array(
  'post_type'           => 'any',
  'post_status'         => 'publish',
  'ignore_sticky_posts' => 1,
  'posts_per_page'      => -1,
  'orderby'             => 'rand',
  'order'               => 'desc',
  'offset'              => 0,
  'tax_query'           => array(
          array(
                'taxonomy' => 'secondary-listing-category',
                'field'    => 'slug',
                'terms'    => 'business-services',
                'operator' => 'IN',
          ),
      ),
  );

This means that the looper will return any items that have the “Business Taxonomy” taxonomy.

Best Regards.