How to show a random selection of posts from the search

I want to show only a random selected number of search results from a search. Its different to the random output from a category. Any Ideas how to do this? it is for a big database to give every post of the search result the chance to be viewed.

Related posts

Leave a Reply

1 comment

  1. This is easy to do using the pre_get_posts action hook to set the orderby to rand in the query, something like this:

    function random_search_result( $q ) {
        if ( is_search() && is_main_query() )
            $q->set( 'orderby', 'rand');
    }
    add_action( 'pre_get_posts', 'random_search_result' );