WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Am trying to display posts only from the "latest" category on my wordpress blog but am strangely getting the same post displayed twice. What am i doing wrong? enter image description here

* Theme file:index.php
    global $post;
    foreach($categories as $categories_item)
        if(strcasecmp($categories_item->name, 'latest') == 0)//case-insensitive string comparison
            $args = array(
            'numberposts'     => 2,
            'category'        => $categories_item->cat_ID,
            'orderby'         => 'post_date',
            'order'           => 'ASC',
            'post_status'     => 'publish'
                $latest_stuff = get_posts( $args );
                echo "<h2>Latest stuff</h2>";
                foreach($latest_stuff as $latest_stuff_item)
                    echo "<div>".the_content()."<div><hr>";
share|improve this question
Does the post posted on multiple categories? – Sisir Nov 1 '11 at 6:51
try to deactivate all plugins to eliminate that influence. – Michael Nov 1 '11 at 8:09

Without looking at the database data (posts, inherits, etc), it's a bit of guesswork.

Try the following:

  • Make sure you have "post_type"=>"post" specified, so that you don't get auto-saved inherits (if it defaults to 'any').
  • If this is an isolated query (not meant to be main loop), use $q = new WP_Query() and run it through that instead of get_posts().
  • What does setup_postdata do? Does it accidentally rewind anything?
  • Try escaping the category loop and apply get_category_by_slug('latest') to "category" (it returns an object with ID) to the call.
share|improve this answer

Your Answer


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.