tax_query shows no results if nothing is selected

So far good, add taxonomy condition by checking the suburbs and states Value. // Suburbs if( !empty( $_GET[‘suburbs’] ) ) { $suburbs = $_GET[‘suburbs’]; } // States if( !empty( $_GET[‘states’] ) ) { $states = $_GET[‘states’]; } // Query arguments. $args = array( ‘post_type’ => ‘properties’, ‘posts_per_page’ => 10, ); $taxquery = array(); // if … Read more

Pagination not working on custom query

The pagination functions work off of the main query, so you’d need to use pre_get_posts instead of creating a new query for them to work. But, you’re using WP_User_Query, so the standard pagination system will never work for you. You’re going to have to ‘roll your own’ pagination system here, and generate your own URLs … Read more

Search Issue in the theme

Every request sent to http://example.com/?s=string will result in a search query, WordPress will use the search.php to render the output. It doesn’t matter where the request is came from. If you need to do an AJAX search, you have to write your own function to do the search and then return it. I have an … Read more

Noindex, nofollow stuck on homepage

The setting is stored in the options table under the key blog_public, the value is either 0 or 1. You can see the value of all options by manually visiting the page /wp-admin/options.php. A quick way to get rid of it would be to remove the noindex action hooked to wp_head, which is what outputs … Read more

Multiple search queries on one page

You can use pre_get_posts to modify the main query, but you will need to create new queries for the other searches. Use get_query_var(‘s’) to get the search terms and create new WP_Query objects to perform your search. Without more information it is hard to provide much more detail to the answer.

Block search SQL from happening

It’s possible to avoid SQL execution in WP_Query with the posts_pre_query filter. It’s e.g. used by plugins to outsource the default search to 3rd party search engines. Here’s an example how we can override the main search query on the front-end, with an empty posts array and avoid running the SQL search query: add_filter( ‘posts_pre_query’, … Read more

How to add WooCommerce SKU to search query?

If you are using wordpress search you can add this code to make it work function search_by_sku( $search, &$query_vars ) { global $wpdb; if(isset($query_vars->query[‘s’]) && !empty($query_vars->query[‘s’])){ $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘product’, ‘meta_query’ => array( array( ‘key’ => ‘_sku’, ‘value’ => $query_vars->query[‘s’], ‘compare’ => ‘LIKE’ ) ) ); $posts = get_posts($args); if(empty($posts)) … Read more