This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Number of search results

  • Creator
    Topic
  • #8919
    J. Weidlein
    Participant

    How can I set the number of search results to something more than 10? I was able to do this with the previous release of Jumpstart by setting ‘posts_per_page’ just before entering the loop in a child copy of search.php, but this no longer works. The number of posts per page defined in the dashboard -> settings -> reading also has no affect. What is the best way to do this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #8937
    Jason Bobich
    Keymaster

    Hello,

    The theme does not modify anything in this regard, I don’t believe. Unless you have something changing this default WordPress querying, this should be corresponding to the option:

    Settings > Reading > Blog pages show at most

    In order to change the posts per page specifically for search results, you’d want to hook onto pre_get_posts.

    This could look something like this:

    function my_pre_get_posts( $q ) {
    
    	if( $q->is_main_query() && $q->is_search )
    		$q->set( 'posts_per_page', 5 );
    
    }
    add_action( 'pre_get_posts', 'my_pre_get_posts' );

    Note: Untested! Just spitballing. 😉

    #8938
    J. Weidlein
    Participant

    thanks Jason – duh, I just realized it was the search plugin I was testing that was overriding what I was doing!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.