I’m using the basic loop code in a taxonomy archive (artists) and I was wondering how you can set the loop to show posts in random order (‘orderby’=>’rand’) it doesn’t seem to work when I add the array? Any help would be great!
<?php
// Start the Loop.
while ( have_posts() ) : the_post();
/*
* Include the post format-specific template for the content. If you want to
* use this in a child theme, then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
array ( 'orderby' => 'RAND' );
get_template_part( 'content', get_post_format() );
endwhile;
// Previous/next page navigation.
twentyfourteen_paging_nav();
else :
// If no content, include the "No posts found" template.
get_template_part( 'content', 'none' );
endif;
?>
more info for query
query_posts(array(
‘showposts’ => 6,
‘orderby’ => ‘rand’,
‘category_name’ => ‘News’ //You can insert any category name
));
Nice Question first !
You can do that with simple using function of PHP.
http://www.php.net/manual/en/function.shuffle.php
Follow below step:
http://www.php.net/manual/en/function.shuffle.php
Please ask me after implementation if any query.
Thanks !
Try this:
?>
You have two ways of doing it. The first way is not the best way, but it may be simpler for you to understand:
Using WP_Query
Here, we’ll be using a custom
WP_Query
object andorderby
to get random posts.Using pre_get_posts
The best way to do it is by using the
pre_get_post
action to modify the page output automatically. You might need some more coding though.