Skip to main content
added 257 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

You are using get_the_term_list which generates an HTML string of taxonomy terms associated with a post and given taxonomy.

Try instead to feed the terms input parameters of the WP_Query with an array like:

'terms' => array( 11, 22, 33 ),

or

'terms' => array( 'term1', 'term2', 'term3' ),

In your code example you have

'terms' => $post_product

so you could use something like this

$post_product_terms = get_the_terms( $post->ID, 'product' );
$post_product = array();
foreach( $post_product_terms as $term ){
    $post_product[] = $term->term_id;>slug;    
}

to construct the $post_product array.

If you want to exclude some terms you can use

'operator' => 'NOT IN',

so your example could be:

array(
    'taxonomy' => 'product',
    'field' => 'slug',
    'terms' => $post_product,
    'operator' => 'NOT IN',
)

You are using get_the_term_list which generates an HTML string of taxonomy terms associated with a post and given taxonomy.

Try instead to feed the terms input parameters of the WP_Query with an array like:

'terms' => array( 11, 22, 33 ),

or

'terms' => array( 'term1', 'term2', 'term3' ),

In your code example you have

'terms' => $post_product

so you could use something like this

$post_product_terms = get_the_terms( $post->ID, 'product' );
$post_product = array();
foreach( $post_product_terms as $term ){
    $post_product[] = $term->term_id;    
}

to construct the $post_product array.

You are using get_the_term_list which generates an HTML string of taxonomy terms associated with a post and given taxonomy.

Try instead to feed the terms input parameters of the WP_Query with an array like:

'terms' => array( 11, 22, 33 ),

or

'terms' => array( 'term1', 'term2', 'term3' ),

In your code example you have

'terms' => $post_product

so you could use something like this

$post_product_terms = get_the_terms( $post->ID, 'product' );
$post_product = array();
foreach( $post_product_terms as $term ){
    $post_product[] = $term->slug;    
}

to construct the $post_product array.

If you want to exclude some terms you can use

'operator' => 'NOT IN',

so your example could be:

array(
    'taxonomy' => 'product',
    'field' => 'slug',
    'terms' => $post_product,
    'operator' => 'NOT IN',
)
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

You are using get_the_term_list which generates an HTML string of taxonomy terms associated with a post and given taxonomy.

Try instead to feed the terms input parameters of the WP_Query with an array like:

'terms' => array( 11, 22, 33 ),

or

'terms' => array( 'term1', 'term2', 'term3' ),

In your code example you have

'terms' => $post_product

so you could use something like this

$post_product_terms = get_the_terms( $post->ID, 'product' );
$post_product = array();
foreach( $post_product_terms as $term ){
    $post_product[] = $term->term_id;    
}

to construct the $post_product array.