Tag Info

New answers tagged

0

Why you are using this filter code, WordPress will still use searchform.php code, without it? Further, it could be some issue with the loop code within search.php. Twentyfourteen theme looks for content-[post-format].php file. Do you have one in you theme root? get_template_part( 'content', get_post_format() ); try using this simplified loop in ...


1

The default search is handled by WP_Query mostly by a method called parse_search(), which is triggered by the s parameter. You can search the source of WP_Query for is_search and piece together a few other bits and pieces. Or you can just create a query... $s = new WP_Query(array('s' => 'test')); ... dump the SQL... var_dump($s->request); ... ...


1

The problems on set a query parameter to unexistent value are 2: The query will run, so even if you already know will be no results there is a little performance price to pay WordPress queries has 19 different 'posts_*' filter hooks ('posts_where', 'post_join', etc..) that act on query, so you can never be sure that even setting unexistent param the query ...


2

Try 'post__in' => array(0) Simple and to the point.


1

Curiously there is no clean/explicit way to short circuit WP_Query. If it's main query you might work something out around WP->parse_request(), there seems to be relatively recent (3.5) do_parse_request filter there. But for WP_Query itself dirty hacks are usually in order, such as short-circuiting SQL query by adding AND 1=0 via posts_where filter, ...


0

You can simply include a custom search function into your search by using pre_get_posts You can do something like this function search_filter($query) { if ( !is_admin() && $query->is_main_query() ) { if ($query->is_search) { $query->set('post_type', 'your-custom-post-type' ); } } } ...


4

A meta_query is an array of arrays. You only have an array. $query->set('meta_query', array( 'key' => 'shru_price', 'value' => $_GET['minPrice'], 'compare' => '>=', 'type' => 'NUMERIC' )); It should be: $query->set( 'meta_query', array( array( 'key' => 'shru_price', ...


0

Use pre_get_posts to filter search results: function search_filter($query) { if ( !is_admin() && $query->is_main_query() ) { if ($query->is_search) { $query->set('post_type', 'custom_post_type_name'); $query->set('cat', intval($_POST['cat']); // assuming you have a select with categories with name "cat" } } } ...


0

If you transform your main website's Wordpress into a multi-site environment, you can move blog.yourdomain.com to be a network site. Once you do this, you could use the Multisite Global Search plugin to add a widget that searches all network sites. It would be easy to move your standalone blog.yourwebsite.com to a network site: export the content from ...


1

Creating custom search is not the easiest of tasks for beginners. You will need templates search.php and searchform.php - View Codex. You can then edit searchform.php and add any fields you need. When the user submits the form it will also add any extra fields you have - so your search url may look something like this /?s=1000&num=5&type=years ...


2

I think this is what you want. base is set via home_url(), format is page/%#%/, search query arg is added via add_args if it exists: $args = array( 'base' => home_url( '/%_%' ), 'format' => 'page/%#%/', 'current' => max( 1, get_query_var('paged') ), 'total' => $temp->max_num_pages, ); if( isset($_GET['s']) ){ ...


0

If the results page isn't using a GET function to actually use the "s" parameter from the URL, why couldn't you just set it as a default value (e.g., foobar) and make it hidden on the form? <form action="/"> <input type="hidden" name="s" value="foobar" /> <input type="number" name="max_price" value="0" min="0" /> <input ...


0

The solution was to create my own search function with wp_query(), it seems to be the easiest solution.


0

It does't work because you can't use set to change all query vars. Simplest way to do the trick is set 's' to an empty string: add_action( 'pre_get_posts', function( $query ) { if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) { $taxquery = array( ... ); $query->set( 'tax_query', $taxquery ); ...


1

In Google Site search, you can set up Refinements ( Edit Search engine - > Search Features -> Refinements tab. You can also set synonyms and promotions (so that particular pages will always appear at the top of specific search results pages). The Google content is based on spidering though, so it won't understand back-end concepts such as 'tags' or ...



Top 50 recent answers are included