Use custom query if main search query returns zero results in wordpress

Exactly right about resetting it! You should use wp_reset_query(). Try this: $num_res = $wp_query->post_count; $get_search_term = get_search_query(); // No more work required for the query, so… wp_reset_query(); if($num_res == 0) { $args = array( ‘post_type’ => ‘resources’, ‘meta_key’ => ‘resource_txt’, ‘meta_value’ => $get_search_term, ‘meta_compare’ => ‘LIKE’ ); $custom_query = new WP_Query( $args ); // Do … Read more

Mysql Queries per Visit – Crazy High

It goes against the grain here to recommend plugins but that’s what you need here. To view in the browser; https://wordpress.org/plugins/query-monitor/ To view in WP-CLI; https://runcommand.io/wp/query-debug/ Both of these will list the queries and how long each one takes. That should give you enough information to make informed decisions about what to do in your … Read more

CONCAT_WS in custom sql query

‘CONCAT_WS(‘,’, wp_postmeta.meta_key, wp_postmeta.meta_value)’ was the name of the column. Everything is working as it should. To change the name of the column, add AS name after the CONCAT_WS statement, like this: ‘CONCAT_WS(‘,’, wp_postmeta.meta_key, wp_postmeta.meta_value)’ AS name (I didn’t test this specifically). Now the new column will be called name.