How to control WordPress Search Behavior?

What you tried to use is broken. add_filter( ‘pre_get_posts’, ‘modified_pre_get_posts’ ); function modified_pre_get_posts( WP_Query $query ) { if ( $query->is_search() ) { $query->set( ‘post_type’, array( ‘page-home’ ) ); } return $query; } That function definition is not valid. You would have seen an error if you had debugging enabled. You need: add_filter( ‘pre_get_posts’, ‘modified_pre_get_posts’ ); … Read more

Search results URL without query string variables

It’s better to share some of your code that already you used. And you mention first line that you have search page ? what exactly you mean by that ? WordPress have default search page did you mention that one ? if you are then try this code function change_search_url_rewrite() { if ( is_search() && … Read more

search only pages if on page

You can append post_type to the end of your search string like this: http://yourdomain.com/?s=search+string&post_type=page This works like a charm: <form method=”get” action=”<?php echo home_url();?>”> <input type=”text” name=”s” /> <label>Search Pages</label> <input type=”radio” name=”post_type” value=”page” /> <label>Search Posts</label> <input type=”radio” name=”post_type” value=”post” /> <button type=”submit”>Submit</button> </form> You could also do something like this within the form … Read more

Adding arg to search results page

That site you linked to is completely wrong. You should never ever use query_posts to run any type of query. Take your time and read the following post on this matter: When should you use WP_Query vs query_posts() vs get_posts()? You also would not want to run any type of custom query in place of … Read more

search.php template not loading results

Change the form to: <input class=”searchform-mid clearit” type=”text” name=”s” id=”search-header” value=”Search” /> Check that name should be “s” as that the get attribute wordpress use for search keyword

Set minimum number of characters in the search

Quick and dirty, put this before your get_header() in your search.php <?php // Get the query string $query = get_search_query(); // if the first & last char is space, rip them $query = trim($query); // if there are more than one space, rip to one space $query = preg_replace(‘/\s\s+/’, ‘ ‘,$query); // if chars count … Read more

Force WP to use a certain search template

You can use template include filter to use it on every search request. Let’s assume the advanced search page template you are using is ‘wp-advanced-search.php’ you can use locate_template to get its path: add_action(‘template_include’, ‘advanced_search_tmpl’); function advanced_search_tmpl( $template ) { if ( is_search() ) { $t = locate_template(‘wp-advanced-search.php’, false); if ( ! empty($t) ) $template … Read more

Include Author profile in search results

If you have a user role called “consultant” and you do a search filtering by capability “consultant”, you wouldn’t find anything. Roles and capabilities are different things. Here is the codex reference: http://codex.wordpress.org/Roles_and_Capabilities

How do I change WP search results order?

You can use the action hook posts_orderby in your child themes functions.php: function changeSearchSort( $orderby, $query ){ global $wpdb; if(!is_admin() && is_search()) { $orderby = $wpdb->prefix.”posts.post_date ASC”; } return $orderby; } add_filter(‘posts_orderby’,’changeSearchSort’,10,2);

Replace URL with Site Title in Search Results

What you are seeing is correct. Google display in SERPs (Search Engine Results Pages) listing as follows: URL Page Title Page Description [ other attributes (potentially) ] Your top result: Tattini Boots – 1860 | Italian English Riding Boots – U.S Links to: https://www.tattiniboots.com/ …your homepage.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)