0

The query below is always returning the latest "news" post, not the latest "news" post with the taxonomy "sotm". I have verified the details of my custom taxonomy, name is "postCat" attached to post type "news", and there is a term "sotm" applied to the post I want to display. Can anyone point out what might be wrong?

    <?php
        $sotmArticle_query = new WP_Query(array(
            'post_type' => 'news',
            'postCat' => 'sotm',
            'orderby' => 'date',
            'order' => 'DESC',
            'posts_per_page' => 1
        ));
        if($sotmArticle_query->have_posts()){
            while($sotmArticle_query->have_posts()){ $sotmArticle_query->the_post();
    ?>
  • You can't just make up parameters. 'postCat' isn't valid - where did you find that? – anu Jul 31 '12 at 13:27
  • postCat is the name of a custom taxonomy – Chuck Jul 31 '12 at 13:32
  • Yes, but you can't just put it there - did you look at the wp_query codex page? See answer below. – anu Jul 31 '12 at 13:33
0

Try something like this:

    $sotmArticle_query = new WP_Query(
      array(
        'post_type' => 'news',
        'tax_query' => array(
                           array(
                                  'taxonomy' => 'postCat', 
                                  'field' => 'slug', 
                                  'terms' => 'sotm'
                           )
                       ),
        'orderby' => 'date',
        'order' => 'DESC',
        'posts_per_page' => 1
     )
    );
    if($sotmArticle_query->have_posts()){
        while($sotmArticle_query->have_posts()){ $sotmArticle_query->the_post();
?>
  • Forehead meets palm, I should have known that, I've done this before, thanks. – Chuck Jul 31 '12 at 13:40

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.