Clear all

[Solved] How Can i show random posts in a category?  



I want show posts in a random order in every category 

1 Answer

Hello Rushish,

By default, WordPress displays the latest posts. In the Cream Blog theme, there is no option to display posts in a category page randomly. If you want to have this functionality then you can copy and paste the code below in the "functions.php" file.

* Filter For Main Query
if( ! function_exists( 'cream_blog_main_query_filter' ) ) :

function cream_blog_main_query_filter( $query ) {

if ( is_admin() ) {

return $query;

if( is_category() ) {

$query->set( 'orderby', 'rand' );

return $query;
add_filter( 'pre_get_posts', 'cream_blog_main_query_filter' );

But we recommend you to do so by creating a child theme and copy and paste the code in the "functions.php" of the child theme. Because when the parent theme is updated the codes no longer be available.

We have already a child theme in Install the theme and in "functions.php" copy and paste the above code.

Best regards.

Thank you it works ❤️

Browse our handcrafted free & pro themes.

Get things done easily with our custom crafted services.

Fall in love with our friendly support team.