WordPress.org

Ready to get started?Download WordPress

Forums

Showing randomly the 5 lastest post (4 posts)

  1. carblanco
    Member
    Posted 2 years ago #

    Hi all,

    I'd like to know how I can show the 5 lastest post by randomly ordered.
    If I add the orderby=rand then I get a randomly ordered list from all the post.

    Thanks.

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

  3. carblanco
    Member
    Posted 2 years ago #

    Thanks but with this WP_Query('cat=1&offset=0&posts_per_page=5&orderby=rand'); I get 5 post randomly ordered, no matter the date. I need to show only the last 5 post but randomly ordered instead of ordered by date.

  4. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    i can only think of a workaround, such as:

    <?php
    $tmp = $post;
    $latest = get_posts('cat=1&offset=0&posts_per_page=5');
    shuffle($latest);
    	foreach($latest as $post) {
    	setup_postdata($post);
    	/*OUTPUT*/
    	}
    $post = $tmp;
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags