WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Advanced Search to Taxonomy Archive (9 posts)

  1. Travis Smith
    Member
    Posted 1 year ago #

    I am using WordPress 3.4.1 & Shopp 1.2.3.

    So I have an advanced search (http://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: http://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 (http://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 http://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(http://lordsnet.staging.wpengine.com/?shopp_manufacturer=lucent&shopp_machine_family=0&shopp_category=forwarding-media&debug && http://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.

  2. Travis Smith
    Member
    Posted 1 year ago #

  3. Travis Smith
    Member
    Posted 1 year ago #

    Of course, if the search parameter is empty I could use template_redirect to the taxonomy archive. That solves it!

    add_action( 'template_redirect', 'lordsnet_empty_search_redirect', 1 );
    function lordsnet_empty_search_redirect() {
    
    	if ( isset( $_GET['pw-search'] ) && isset( $_GET['s'] ) && empty( $_GET['s'] ) ) {
    		$qvs = array();
    		foreach( $_GET as $param => $value ) {
    			if ( 'pw-search' != $param && 's' != $param && 's_cs' != $param )
    				$qvs[$param] = $value;
    		}
    		$url = add_query_arg( $qvs, home_url() );
    
    		wp_redirect( $url );
    		exit;
    	}
    }
  4. Andrew Nacin
    Lead Developer
    Posted 1 year ago #

    Is your issue that you did not set is_tax to true originally?

  5. Travis Smith
    Member
    Posted 1 year ago #

    Nacin, no I tried that. I believe the issue was that the query had run already and the queried object wasn't what was needed. It was as if parse_query was too late or something...This is on a stage and I don't mind sharing if you'd like to run some tests or something?

  6. Travis Smith
    Member
    Posted 1 year ago #

    nacin, any idea why http://lordsnet.staging.wpengine.com/?shopp_manufacturer=cisco&shopp_category=adapter-card (add &debug to see the main query) has *posts* (rather products) where shopp_manufacturer is NOT cisco? This page should have no posts, but it shows posts as though the URL is http://lordsnet.staging.wpengine.com/?shopp_manufacturer=lucent&shopp_category=adapter-card ??

  7. Travis Smith
    Member
    Posted 1 year ago #

  8. Jonathan
    Member
    Posted 1 year ago #

    I think this is a Shopp-specific issue related to the multiple taxonomy query. We're getting a patch together now.

  9. Travis Smith
    Member
    Posted 1 year ago #

    Moving this to Shopp forums.

Topic Closed

This topic has been closed to new replies.

About this Topic