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.

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();
    ?>
share|improve this question
    
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
add comment

1 Answer

up vote 0 down vote accepted

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();
?>
share|improve this answer
    
Forehead meets palm, I should have known that, I've done this before, thanks. –  Chuck Jul 31 '12 at 13:40
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.