Advanced Search to Taxonomy Archive
-
I am using WordPress 3.4.1 & Shopp 1.2.3.
So I have an advanced search (https://lordsnet.staging.wpengine.com/inventory/) where I am allowing the user to search by custom taxonomies with a keyword search. However, if the user selects only the custom taxonomies with no keyword, the results render no results.
So if you select a manufacturer and a category and click search you get no results (URL: https://lordsnet.staging.wpengine.com/?shopp_manufacturer=lucent&shopp_machine_family=0&shopp_category=forwarding-media&s=&pw-search=advanced-search&s_cs=true) because the search query var is empty. {Note to see wp_query, add &debug to the end (https://lordsnet.staging.wpengine.com/?shopp_manufacturer=lucent&shopp_machine_family=0&shopp_category=forwarding-media&s=&pw-search=advanced-search&s_cs=true&debug).}
However, what I would like is for the results in this scenario is to switch from is_search to an is_tax, where the page that displays is the equivalent to removing s=, pw-search=, and s_cs=, so that the resulting URL is https://lordsnet.staging.wpengine.com/?shopp_manufacturer=lucent&shopp_machine_family=0&shopp_category=forwarding-media
I then modified the parse_query:
add_action( 'parse_query', 'lordsnet_empty_search', 999 ); function lordsnet_empty_search( &$query ) { if ( isset( $_GET['pw-search'] ) && isset( $_GET['s'] ) && empty( $_GET['s'] ) && $query->is_main_query() ) { // Remove Search query unset( $query->query['s'] ); unset( $query->query_vars['s'] ); // Remove Shopp Search query unset( $query->query['s_cs'] ); unset( $query->query_vars['s_cs'] ); $query->is_search = false; $query->shopp_page = true; } return $query; }
This basically says, from my understanding, that I removed the search and the Shopp search query vars from the query. Then I noticed that the queried object was wrong. So I changed it to this:
add_action( 'parse_query', 'lordsnet_empty_search', 999 ); function lordsnet_empty_search( &$query ) { if ( isset( $_GET['pw-search'] ) && isset( $_GET['s'] ) && empty( $_GET['s'] ) && $query->is_main_query() ) { // Remove Search query unset( $query->query['s'] ); unset( $query->query_vars['s'] ); // Remove Shopp Search query unset( $query->query['s_cs'] ); unset( $query->query_vars['s_cs'] ); $query->is_search = false; $query->shopp_page = true; unset( $query->queried_object ); $query->queried_object = $query->get_queried_object(); } return $query; }
Doing this makes the main query the same on both URLs(https://lordsnet.staging.wpengine.com/?shopp_manufacturer=lucent&shopp_machine_family=0&shopp_category=forwarding-media&debug && https://lordsnet.staging.wpengine.com/?shopp_manufacturer=lucent&shopp_machine_family=0&shopp_category=forwarding-media&s=&pw-search=advanced-search&s_cs=true&debug), but what is being displayed is not correct.
- The topic ‘Advanced Search to Taxonomy Archive’ is closed to new replies.