query multiple taxonomies

First of all, get all term slugs from the custom taxonomy space by current post ID.

$space_terms = wp_get_post_terms( $post->ID, 'space' );
if( $space_terms ) {
  $space_terms = array();
  foreach( $space_terms as $term ) {
   $space_terms[] = $term->slug;
  }
}

You should specify the logical relationship between each inner taxonomy array when there is more than one.

The relation key in the array describes the relationship. Possible values are OR and AND.

'tax_query' => array(
    'relation' => 'OR',
    array(
        'taxonomy' => 'products-category',
        'field'    => 'slug',
        'terms'    => $course_terms,
    ),
    array(
        'taxonomy' => 'space',
        'field'    => 'slug',
        'terms'    => $space_terms,
    ),
),

Leave a Comment