Answers for "wp_query random posts"

PHP
1

get random posts wordpress

$randomPosts = get_posts(array(
   'orderby' => 'rand',
   'posts_per_page' => 5,
   'tag' => $tag,
));
Posted by: Guest on July-29-2021
0

wordpress php query randomise

//Create WordPress Query with 'orderby' set to 'rand' (Random)
$the_query = new WP_Query( array ( 'orderby' => 'rand', 'posts_per_page' => '1' ) );
// output the random post
while ( $the_query->have_posts() ) : $the_query->the_post();
    echo '<li>';
    the_title();
    echo '</li>';
endwhile;

// Reset Post Data
wp_reset_postdata();
Posted by: Guest on February-27-2021

Browse Popular Code Answers by Language