WordPress.org

Forums

[resolved] Sidebar problem: get_posts function not working properly! Please help.. (3 posts)

  1. Rage00001
    Member
    Posted 7 years ago #

    Ok..
    I have this in my sidebar, and this have been working fine for over one year and many versions of WP.

    <ul>
     <?php
     $myposts = get_posts('numberposts=20&offset=5');
     foreach($myposts as $post) :
     ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
     </ul><br />

    I think the problem started when we changed to the year 2008.

    Now it's totally wrong, and don’t show the just archived post with an offset of 5. The post shown there are really old...

    look here: http://www.sinna.no

    Thanks for all help :)

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    This is the MySQL 5.0.50/51 bug. Looks like your host just upgraded their MySQL version. Unfortunately a lot of hosts are upgrading MySQL now, and they're all doing it to these buggy versions. WordPress is doing the right thing, their version of MySQL is not.

    Quick hack/fix:
    Find this in wp-includes/post.php (around line 260):
    $query .= " GROUP BY $wpdb->posts.ID ORDER BY " . $orderby . ' ' . $order;

    Change it to this:
    $query .= " ORDER BY $orderby $order";

    That should solve it. But this is a temporary fix only, some other types of get_posts calls won't work with this fix.

    Meanwhile, tell your host that they need to upgrade to at least MySQL version 5.0.52, because 5.0.50 and 51 have a bug that causes this problem: http://bugs.mysql.com/bug.php?id=32202

    If your host wants more information, tell them to come here and ask. We'll tell them all about it.

  3. Rage00001
    Member
    Posted 7 years ago #

    Thank You!!
    when i changed the code as you told me, everything is just fine as it should be...

Topic Closed

This topic has been closed to new replies.

About this Topic