Querying on multiple taxonomies pulled from $_GET checkbox array not working?

Here: $search_values[‘tax_query’] = array ( You’re resetting the value of tax_query for every item in the foreach loop. It’s also being set to an invalid value: Important Note: tax_query takes an array of tax query arguments arrays (it takes an array of arrays). This construct allows you to query multiple taxonomies by using the relation … Read more

I did group my search results by post type, but how can i give each of them its own order?

Here’s one suggested high level approach to get the desired effect. Rather than perform all your operations in one big while loop in your searchresults.php, try: establishing three arrays corresponding to each type- you can do this in one while loop. then sort each array as needed (refer to PHP’s Sorting Arrays documentation for the … Read more

How get get list of pages in ajax search

There is no get_pages() method in the WP_Query class (for WordPress version 4.9.4). So in the data_fetch() function, replace the following: if( $the_query->get_pages() ) : while( $the_query->get_pages() ): $the_query->get_pages(); ?> ..with this: if( $the_query->have_posts() ) : while( $the_query->have_posts() ): $the_query->the_post(); ?> And in the fetch() JS function, set the type to POST, like so: function … Read more

if statement for search results

Within the loop the best way to check if the result is a product would be to check the value of get_post_type(): if ( get_post_type() === ‘product’ ) { } As you say, is_woocommerce(), is_product() and is_search() are for checking which type of page is being viewed regardless of the current item in the loop.

WordPress Search matching hyphenated words

It is possible to filter search terms before they are submitted to the actual query using the query_vars hook. So in your case you would do something like this: add_filter (‘query_vars’, ‘wpse307005_filter_search’, 10, 1); function wpse307005_filter_search ($args) { preg_replace (‘Spiderman’,’Spider-Man’,$args[s]); preg_replace (‘Spider man’,’Spider-Man’,$args[s]); return $args; } Where $args[s] holds the search string.

Keep query string in url after executing a serch

It’s hard to say how to do it exactly in your case, because we don’t know how your form is generated… But in general you have to add a hidden input to that form. So if you use searchform.php in your theme, then add something like this to it: <input type=”hidden” name=”name” value=”<?php echo esc_attr( … Read more

Redirect All Search Links Containing – to + on WordPress

You can do something like the following at the top of your .htaccess file to replace all – with + that occur after the /search/ path segment in the requested URL: RewriteRule ^(search/[^-]*)-([^-]*-.*) /$1+$2 [N] RewriteRule ^(search/[^-]*)-([^-]*)$ /$1+$2 [R=302,L] The first RewriteRule loops (internally) until all except 1 hyphen has been replaced with +. The … Read more

Only show search results with if current date is between two dates?

You can use meta queries to filter posts according to your needs. Here is a sample code: function SearchFilter( $query ) { if ( !is_admin() && $query->is_search ) { $query->set( ‘post_type’, ‘visitor’ ); $query->set( ‘meta_query’, array( ‘relation’ => ‘AND’, array( ‘key’ => ‘visitor-start-date’, ‘value’ => time(), ‘compare’ => ‘<=’ ), array( ‘key’ => ‘visitor-date’, ‘value’ … Read more