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.

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;
    $categories=get_categories();
    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)
                {
                    setup_postdata($post);
                    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
add comment

1 Answer

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
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.