0

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,
),
),));
  • 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
2

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.

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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