Wordpress get posts not in custom taxonomy term

The following code is supposed to get posts that do not have specific terms in a custom taxonomy. At the moment it still gets them. Is something missing.

$args = array(
            'numberposts' => '3',
            'post__not_in' => $post_not_in,
            'tax_query' => array(
                'taxonomy' => 'topic',
                'terms' => 9,      
                'field' => 'id',
                'operator' => 'NOT IN'
            ) 
        ); 
        $extras = get_posts($args);

Answers


Important Note: tax_query takes an array of tax query arguments arrays (it takes an array of arrays)

Wordpress Codex on Taxonomy Parameters

Have you tried?

$args = array(
    'numberposts' => '3',
    'post__not_in' => $post_not_in,
    'tax_query' => array(
        array(
            'taxonomy' => 'topic',
            'terms' => 9,      
            'field' => 'id',
            'operator' => 'NOT IN'
        )
    )
); 
$extras = get_posts($args);

Need Your Help

How to disable Excel's auto recognition of numbers and text

python excel

I used Python to generate a CSV file. But when I open it in Excel, Excel will auto recognize a string into a number if it could be converted.