mardi 14 avril 2015

How to Show random post on WordPress, except the last published post

I have a website where people can upload articles, but I would like to show a random post, except the last published post on the main page, because if all the post are random, the user can not see his post when recently uploaded.


I was able to locate this, this is the one that I'm currently using



add_action('pre_get_posts', 'my_pre_get_posts');
function my_pre_get_posts($query) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set('orderby', 'rand');
}
}




Aucun commentaire:

Enregistrer un commentaire