Answer the question
In order to leave comments, you need to log in
How to shuffle recent posts in wordpress?
The entries are output as follows:
$args=array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'posts_per_page' => 10,
'showposts'=>2,
'orderby'=>'date'
);
Answer the question
In order to leave comments, you need to log in
$posts = get_posts( array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'posts_per_page' => 10,
'orderby' => 'date'
) );
// получаем два случайных ключа из массива
$rand_keys = array_rand($posts, 2);
foreach ( $posts as $key => $post ) {
if ( in_array( $key, $rand_keys ) ) {
echo '<h2 class="post-title">' . $post->post_title . '</h2>';
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question