Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to show a list of custom posts but exclude any that have the custom taxonomy 51, is it possible to do it with the loop below?

$pages = get_children(array('orderby' => 'post_date', 'post_type' => 'news', 'numberposts' => "3"));
$counter = 1;                               
foreach($pages as $post) {
    setup_postdata($post);
    $fields = get_fields();
}

UPDATE:

The custom taxonomy is called opportunity and has the term id 51 in the custom taxonomy. If this helps - this is how I'm grabbing all the custom post's with the custom taxonomy opportunity:

$pages = get_children(array(
'orderby' => 'post_date', 
'post_type' => 'news',
'post_status' => 'future',
'numberposts' => "3",
'tax_query' => array(
array(
'taxonomy' => 'news',
'field'    => 'id',
'terms'    => 51,
),
),));
share|improve this question
    
Is "51" the name of a custom taxonomy, the ID of a term in a custom taxonomy, or the ID of a term in the Categories or Tags taxonomies? Please clarify your question and include the name of the taxonomy as well for easier reference. –  mrwweb May 10 '12 at 18:29
    
@mrwweb Sorry, updated my question. –  Rob May 10 '12 at 18:37
add comment

1 Answer

up vote 2 down vote accepted

Make sure to reread the tax_query documentation. If you change it to this, I think it should work:

'tax_query' => array(
    array(
        'taxonomy' => 'news',
        'field'    => 'id',
        'terms'    => 51,
        operator => 'NOT IN'
    )
)

Depending on your setup, you may also want to specify the include_children argument.

share|improve this answer
    
Cool cheers thanks. Can't believe I didn't see that! Thanks again! –  Rob May 10 '12 at 19:59
    
Glad I could help. Those codex pages can all start blurring together after a while :) –  mrwweb May 10 '12 at 20:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.