• I am trying to run a query to display posts from a custom post type that do not have any terms from a custom taxonomy associated with them. Here is the code.

    $args = array(
    'fields' => 'ids',
    'orderby'=> 'id',
    'order' => 'ASC',
    'hideempty' => 0
    );
    $term_ids = get_terms( 'people', $args);
    
    $args = array(
    	'post_type' => 'organizations',
    	'tax_query' => array(
    		array(
    		'taxonomy' => 'people',
    		'terms' => $term_ids,
    		'operator' => 'NOT IN'
    		))
    );

    In the result I get entries from the first term id. So it seems like $term_ids is an array so it is probably getting only the first term id? But if it is getting the first term ID then it should not display posts from it. Instead it should display posts from other terms.

    Please point out what I am doing wrong?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You should provide a ‘field’ parameter in the tax_query indicating you are providing term IDs and not term slugs as terms parameters.

    This does not explain the results you are getting so there may be something else going on. In any case you need to provide the ‘field’ parameter.

Viewing 1 replies (of 1 total)
  • The topic ‘Getting Term IDs in WP_Query’ is closed to new replies.