Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limiting WordPress search result items

Tags:

wordpress

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?

like image 386
Pointer Avatar asked Jul 22 '17 15:07

Pointer


People also ask

How do I change my search settings on WordPress?

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.

How do I create a custom search in WordPress?

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.

How do I limit Google search results?

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.


1 Answers

Changing The Number Of Results Per Page

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' );
like image 184
Purvik Dhorajiya Avatar answered Sep 28 '22 07:09

Purvik Dhorajiya