WordPress.org

Ready to get started?Download WordPress

Forums

get_posts doesn't work after 2.6 upgrade (4 posts)

  1. tylerhauser
    Member
    Posted 6 years ago #

    So I just updated my WP version to 2.6 and a function I used in my sidebar to call the latest post from 2 specific categories doesn't seem to work any longer. Instead of getting the latest post from my chosen categories, I get the latest post globally.

    http://twowordheap.com

    Here's the code I used:

    <?php $lastposts = get_posts('numberposts=1&category=7&orderby=post_date&order=DESC');
    foreach($lastposts as $post) :
    setup_postdata($post);
    ?>
    
    <p>
    
    <?php the_title(); ?>
    
    <?php if ($post->post_excerpt) :
    $output = $output = $post->post_excerpt;
    $output .= ' <a href="http://www.twowordheap.com/category/site-news/" title="Continue reading...">Continue reading...</a>';
    echo apply_filters('the_excerpt',$output);
    else:
    the_content();
    endif;
    ?>
    
    </p>
    
    <?php endforeach; ?>

    The whole post excerpt section is something concocted in these very forums and has worked without a problem since I implemented it. I don't think it is causing any problems as I can switch it out with just the_content() and I still get the same problem (you know, just with the entire post instead of the excerpt).

    Any ideas?

  2. Hafiz Rahman
    Member
    Posted 6 years ago #

    Seems like get_posts() is broken by the 2.6 release. This happens on various sites too (wpcandy.com to mention one). I think a temporary fix for creating multiple loop is by using the query_posts() instead.

  3. scrstudios
    Member
    Posted 6 years ago #

    I too have the same problem after upgrading...

  4. tylerhauser
    Member
    Posted 6 years ago #

    Awesome! Thanks Hafiz! Using query_posts() definitely works as a temporary fix. Here's the code I used...

    <?php $my_query = new WP_Query('category_name=site-news&showposts=1'); ?>
    
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <p><?php the_title(); ?>
    
    <?php if ($post->post_excerpt) :
    $output = $output = $post->post_excerpt;
    $output .= ' <a href="http://www.twowordheap.com/category/site-news/" title="Continue reading...">Continue reading...</a>';
    echo apply_filters('the_excerpt',$output);
    else:
    the_content();
    endif;
    ?>
    
    </p>
    
    <?php endwhile; ?>

    I wonder what broke get_posts()...

Topic Closed

This topic has been closed to new replies.

About this Topic