How to limit in WordPress search result page to 5 or 10 items?
Maybe any change in `general-template.php?
Can anyone help with that?
To set up a search engine, go to the SearchWP settings page. Click the new SearchWP button at the top of your WordPress dashboard to access it. You can either choose to create a new search engine or just edit the default engine.
To get started, navigate to Appearance → Widgets to open the widget editor screen: From there, simply find the Search widget in the list and drag it to the area you want to display it in: You get access to the same options here as in the Customizer.
When you need to limit search results, we recommend using tags. Tags are keywords located at the end of various articles and can be used to narrow search parameters. Additionally, since Google handles our primary search results, you can use Google's advanced search techniques, such as AND, NOT, phrases, and more.
By default WordPress uses the number defined under Settings > Reading (blog pages show at most…) to define how many results appear on the search results page. If you would like to show more, less or infinite results on your search page you can do so using the following code:
// Alter search posts per page
function pd_search_posts_per_page($query) {
if ( $query->is_search ) {
$query->set( 'posts_per_page', '10' );
}
return $query;
}
add_filter( 'pre_get_posts','pd_search_posts_per_page' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With