How to Show random post on WP except the last post

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');
        $query->set('post__not_in',array(1));
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *