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.
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.
use the 'posts_per_page' parameter as well
http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters
http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
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.
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;
?>This topic has been closed to new replies.