Create multiple Search functions for posts / custom post types and everything

you can change your search filter to this: function SearchFilter($query) { $post_type = $_GET[‘post_type’]; if (!$post_type) { $post_type=”any”; } if ($query->is_search) { $query->set(‘post_type’, $post_type); }; return $query; } add_filter(‘pre_get_posts’,’SearchFilter’); then on your news search form add : <input type=”hidden” name=”post_type” value=”post” /> on your custom post type listing search form add <input type=”hidden” name=”post_type” value=”customtypename” … Read more

Include images from pages in wp search.php results in default wp search

To include the attachment (media) post type in search results, use the following code snippet function attachment_search( $query ) { if ( $query->is_search ) { $query->set( ‘post_type’, array( ‘post’, ‘attachment’ ) ); $query->set( ‘post_status’, array( ‘publish’, ‘inherit’ ) ); } return $query; } add_filter( ‘pre_get_posts’, ‘attachment_search’ ); Source However, this does not take care of … Read more

Custom search form with empty parameters

That’s certainly something you must solve on the server side, only omitting the arguments in URL would cause errors when accessing the non-existent keys in the $_GET array. You should build your arguments array dynamically based on whether the values are set ot not. Example: $args = array(); foreach(array(‘s’, ‘country’, ‘year’) as $key) { // … Read more

How to redirect search result page to post

I think it is better that you do this inside the WordPress install, not on the .htaccess. Is not easy to maintain and maybe a problem, if you have more results for a search. You can use the follow source, write in a small plugin and activate. If the search result have only one result, … Read more

Search with filters and title

First, you are setting $_GET[‘filterN’] but you are trying to use $_GET[‘condition_N’]. That is not ever going to work right. Secondly, pagename is an “exact match” value, not a search parameter, and it only works with the “Page” post type (at least so far as I can tell). You are using a CPT and, presumably, … Read more

Search not working with title and content

Edit: It appears your actual problem is searching tags and categories, hence placing the s parameter inside the tax_query. There is no way to search tags categories and other terms using only the fields provided by WP_Query. Your query doesn’t work because what you want isn’t possible with just the parameters available. Instead of asking … Read more