Perhaps this
function
will help you out.
Add tofunctions.php
after you made a backup of this file.
There is no need to add any in a template by using this function.
/**
* Set max output results for search page
*
* @param $queryVars
* @return results
*
* Read more @link https://developer.wordpress.org/reference/classes/requests /request/
* Tested with @version 5.3.2
*
*/
add_filter( 'request', 'search_results_pro_page' );
function search_results_pro_page( $queryVars )
{
// Prevent access to back-end
if ( is_admin() ) {
return;
}
// Set only on search
if ( isset( $_REQUEST['s'] ) ) {
// Adjust number of results shown
$queryVars['posts_per_page'] = 4;
}
// Return amount search results
return $queryVars;
}
Related Posts:
- Is it possible to use the featured image of a page as a css background without inlining?
- Switching between custom templates in a post type of the admin menu
- Custom search results page not working with empty search
- I have a problem in the order of enqueues while enqueuing stylesheets and scripts for a specific page in my function.php
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- Use WordPress function in php file
- Search form does not work in my website
- How to call multiple functions from multiple files into a WordPress page template [closed]
- How do I query a single data value from the wp_metadata table?
- Search only working on front page (index) , not working on other pages
- Search page results conflicting logic – Search result caching?
- pass html code to worpdress
- Search.php gets metadata from first post
- Integrate admin plugin into template. Very interesant (live search + autocomplete with wp rest api, in vanilla js)
- Check if current post in loop is last on current page
- What syntax is this? “{{post.price}}”
- How to refresh a template page on WordPress in 3 seconds – easiest method?
- Twig+WordPress how to use array arguments inside a function?
- How can i upload images in an admin page?
- Where to edit the template that is generating the code for dynamic_sidebar left-sidebar in the Understrap theme? [closed]
- WordPress pagination not working with search page
- Multiple WordPress Menus that will only display all pages
- Set the checkbox as checked by default at options page
- Input type search in Menu
- How to make a search button that will search my website?
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Add child pages of parent to navbar PHP
- How can I create a list of page titles from custom meta values?
- Load a page into a div with Ajax
- WordPress Search Results for Multiple Post Types
- WP Query with custom Shortcode
- Custom theme: Alternatives to long list of ‘include’ in functions.php
- Theme Options Page – User Updates Logo
- how could I load a different template part by page
- Converting HTML Template to WordPress Theme
- How to use my style.css file outside of wordpress subdomain?
- How to show part of the_content?
- Wp-login appears White Screen, Error: Cannot modify header information
- creating a second image attachment template?
- How to remove the cufon script from Dzonia Lite theme [closed]
- get_the_tags() not iterating through for/while loop, but will with foreach
- Mass update excerpt
- Customising the search function?
- Hide categories that are not used in the post type
- How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
- How can I get a single php file that is the equivalent of an existing WordPress page?
- How do I add custom bulk actions to multiple custom post types?
- Add_action not working in required file of functions.php
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- adding custom user input fields in WordPress admin dashboard gives error The link you followed has expired. Please try again
- Get and insert order email address to the PHP template inside HTML text
- what is the best practice to add new field to an api route
- Grab posts by multiple categories
- Can’t access variable outside for loop
- add custom link to wordpress media gallery modal
- How to show single category archive
- Need Help Fixing My Iframes [closed]
- code is skipping a div
- Avoid parallax images hardcoding
- Improve page speed loading using CDN and async or defer attribute
- Issues getting PHP to display in category pages
- WordPress default Search function inconsistent in WooCommerce Product Titles
- Save Search System
- populate form fields in a loop with ajax
- Error in custom php function doesn’t exist
- Customizer: active_callback and sanitize_callback incompatibility?
- post created but no permalink
- Seach custom post type posts only by meta fields?
- Change title only in dynamic page
- Populate editor with some content of a page with a page template
- Two queries for a WP_User_Query search work perfectly apart, but not together
- Search not showing all results
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Catchable fatal error: Object of class stdClass could not be converted to string after WP 4.7
- Autocomplete search box
- Secondary navigation menu on one page
- Enable custom logo upload if logo is not in header
- Menu jumping when calling it via PHP
- Displaying recent posts on static page with template-part via shortcode
- How to edit widget code to add unique class name to each div?
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- Skt full width basic slideshow problem
- edit search.php to include subdomain posts
- Search Query: how to construct a search string from two select elements?
- How can I edit the content in index.php? [duplicate]
- How to disable controls in theme customizer?
- How do I link a button I created in theme customizer to a function?
- Trying to retrieve post meta
- Can anyone offer any help with this function?
- can i fetch a custom metabox data in another page or post type?
- Is there a way to conditionally check whether a WordPress post title is empty?
- Woocommerce Show Single Product on Homepage
- how to show only specific category for a template
- Show a different code on front page to other pages
- Does wordpress templates always in files or in database?
- get_template_part for specific page
- How do I create my own .php file with a code part and echo it on different pages?
- Is there any tool to find lines of codes responsible to generate front-end HTML elements?
- Can’t print Yoast meta description into page template (syntax error, unexpected ‘.’) [closed]
- Using same variable names in files added with get_template_part()