Forums Forums Search & Filter Pro Different templates for different filter search

Viewing 9 posts - 1 through 9 (of 9 total)
  • Anonymous
    #31834

    I was wondering if it is possible with Search & Filter Pro to use a different template depending on the filter you are searching.

    For example, let’s say the CPT for the search & filter was credit-cards and the filter was categories using a radio select of Balance Transfer, Rewards, Low APR.

    Depending on which category you select, the results would be displayed differently. Balance transfer would show columns that Rewards and Low APR wouldn’t and so on.

    The only way I was thinking something like this would be possible would be to create a new search form for each category. Are there any other ways this could be done?

    Ross Moderator
    #31845

    Hi Eric

    What you are after is not stricly possible but you can more or less achieve something similar.

    Why not, in your template have a check to see which options have been selected / searched for and conditionally load different content?

    You can check what a user has selected here:
    http://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/

    And you can then load in different template “parts” using this:
    https://codex.wordpress.org/Function_Reference/get_template_part

    Thanks

    Anonymous
    #31852

    Ahh I see. Much appreciated!

    Anonymous
    #31935

    So I’ve been trying to pull the field name from the Active Query Object, but I’m not able to pull any of custom fields, just categories.

    I’m able to get _sft_credit_card_category, but not the post_meta fields of _sfm_issuer and _sfm_credit_quality.

    
    <?php
    //grab the active query from our search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(615)->current_query();
    var_dump($sf_current_query->get_array());
    
    echo $sf_current_query->get_field_string("_sft_credit_card_category");
    echo $sf_current_query->get_field_string("_sfm_issuer");
    echo $sf_current_query->get_field_string("_sfm_credit_quality");
    ?>
    
    Ross Moderator
    #31936

    What are the results from that var_dump?

    Do you see any of the other data in there?

    Thanks

    Anonymous
    #31943
    
    array(5) { 
    
    ["_sft_credit_card_category"]=> array(5) { 
    	["name"]=> string(22) "Credit Card Categories" 
    	["singular_name"]=> string(20) "Credit Card Category" 
    	["all_items_label"]=> string(26) "All Credit Card Categories" 
    	["type"]=> string(8) "taxonomy" 
    	["active_terms"]=> array(1) {
    		[0]=> array(3) { 
    			["id"]=> int(20) 
    			["name"]=> string(16) "Balance Transfer" 
    			["value"]=> string(16) "balance-transfer" 
    			} 
    		} 
    	} 
    
    ["_sfm_issuer"]=> array(5) { 
    	["name"]=> string(0) "" 
    	["singular_name"]=> string(0) "" 
    	["all_items_label"]=> string(0) "" 
    	["type"]=> string(9) "post_meta" 
    	["active_terms"]=> array(1) { 
    		[0]=> array(2) { 
    			["name"]=> string(15) "Bank of America" 
    			["value"]=> string(15) "Bank of America" } 
    		} 
    } 
    
    ["_sfm_credit_quality"]=> array(5) { 
    	["name"]=> string(0) "" 
    	["singular_name"]=> string(0) "" 
    	["all_items_label"]=> string(0) "" 
    	["type"]=> string(9) "post_meta" 
    	["active_terms"]=> array(0) { } 
    
    } 
    
    ["_sf_post_date"]=> array(2) { [0]=> string(0) "" [1]=> string(0) "" } 
    
    ["_sf_sort_order"]=> array(0) { } 
    
    } 
    
    Anonymous
    #31944

    There should be values for _sfm_credit_quality, but they’re not appearing. As you can see, _sfm_issuer has a value.

    Anonymous
    #32036

    I was going through some of the plugin files and saw the function get_post_meta. Any documentation on using these?

    Ross Moderator
    #32138

    Hey Eric

    get_post_meta() is a WP function:
    https://developer.wordpress.org/reference/functions/get_post_meta/

    I’m not sure its what you would need.

    Could you by any chance send me a link to a search page, with a var_dump in the results area so I can see the error in action?

    Thanks

Viewing 9 posts - 1 through 9 (of 9 total)