Random Post from a Specific Category not working in 2.6 (3 posts)

  1. educationthemes
    Posted 7 years ago #

    I have been using this code in WordPress 2.5.1 in order to generate a custom field called testimonial randomly from a certain category:

    <?php $rand_posts = get_posts('cat=7&numberposts=1&orderby=RAND()'); foreach( $rand_posts as $post ) : ?>
    <em>"<?php echo get_post_meta($post->ID, "testimonial", true); ?>"</em>
    <?php endforeach; ?>

    This display a particular custom field from posts in category 7 randomly so they change on each page and refreshes.

    The problem is that now I have upgraded to WordPress 2.6 this no longer gives a random post but just delivers the latest post from the category 7. Anyone any ideas why?

  2. hungzai
    Posted 7 years ago #

    Exactly. This doesn't work in 2.6 anymore! I kinda regret upgraded it!


    This works for me.

  3. hungzai
    Posted 7 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic