Forum

Notifications
Clear all

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

   RSS

0

I want show posts in a random order in every category 

1 Answer
0

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;
}
endif;
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 WordPress.org. Install the theme and in "functions.php" copy and paste the above code.

Best regards.

@themebeez
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.