Skip Navigation

[Resolved] displays terms in wpv-items-found

This thread is resolved. Here is a description of the problem and solution.

Problem:
Is there a way to list the terms selected inside the wpv-items-found so the user would have a quick view of what they have selected?

Solution:
1. Please add this code in your theme’s or child theme’s functions.php file:

 
function get_selected_filter_fun( $atts ) {
   
    // Attributes
    extract(shortcode_atts(
        array(
            'taxonomy' => '',
        ),
        $atts
    ));
     
    if(isset($taxonomy))  {
        $term_value = 'wpv-'.$taxonomy;
        if( isset($_GET[$term_value]) && $_GET[$term_value] != ''){
            $term_details = get_term_by( 'slug', $_GET[$term_value] , $taxonomy);
            return $term_details->name;
        }
    }
    else
        return 'Not selected';
          
}
add_shortcode( 'get_selected_filter', 'get_selected_filter_fun' );
 
 //Loop Counter
add_shortcode('incrementor', 'incrementor');
function incrementor() {
    static $i = 1;
    return $i++;
}

2. Register both shortcodes first ‘get_selected_filter’ and ‘incrementor’ in Toolset >> Settings >> Front-end Content >> Third-party shortcode arguments.

3. Then you can use these shortcodes in the View like this (its recommend to use in “Templates for this View” section since you are using ajax):

[php]
[wpv-conditional if="( '[incrementor]' eq '1' )"]
[get_selected_filter taxonomy="bedcategory"] // replace taxonomy name here
[get_selected_filter taxonomy="gender"]
[/wpv-conditional]

[php]

Other solution could be using Custom jQuery code as client has done here:
https://toolset.com/forums/topic/displays-terms-in-wpv-items-found/#post-562040

This support ticket is created 7 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 9 replies, has 2 voices.

Last updated by nicholasM 7 years, 3 months ago.

Assisted by: Noman.

Author
Posts
#560652

I have a custom search with an Icon for each taxonomy term I'm using but for the sake of making this easier, lets just say I have a taxonomy with 5 terms, I select "term 1" and search via Ajax using submit button. Is there a way to list the terms selected inside the wpv-items-found so the user would have a quick view of what they have selected?

#560780

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Nick,

Thank you for contacting Toolset support. Please provide more information on what you would like to achieve.

Are you using Custom Search View (posts view) >> and would like to display Selected Term at the Top of the page (the term that is selected in the search form filter) >> and show it before search results?

Because the term that we select in search form, is already shown as selected in the form itself.

- Provide back-end screenshot of the View.
- Provide page link where I can see this.

Thank you

#560945

hidden link - This should make sense now that you can see it, there will be multiple taxonomies along the top to select from so I want to have a list on the screen displaying what has been selected.

#560957

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Please also provide this:
- Provide back-end screenshot of the View so I can see the shortcodes used and overall structure.

#561003
Screen Shot 2017-08-17 at 14.42.14-fullpage.png

sorry here you go

#561201

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for providing more details and screenshots. We can display selected Terms on the page by using a custom shortcode. I am working on this right now and will update you with the outcome soon.

Thank you for waiting on this.

#561266

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

We can achieve this by using custom shortcode.

1. Please add this code in your theme’s or child theme’s functions.php file:

function get_selected_filter_fun( $atts ) {
  
    // Attributes
    extract(shortcode_atts(
        array(
            'taxonomy' => '',
        ),
        $atts
    ));
	
	if(isset($taxonomy))  {
		$term_value = 'wpv-'.$taxonomy;
		if( isset($_GET[$term_value]) && $_GET[$term_value] != ''){
			$term_details = get_term_by( 'slug', $_GET[$term_value] , $taxonomy);
			return $term_details->name;
		}
	}
	else
		return 'Not selected';
         
}
add_shortcode( 'get_selected_filter', 'get_selected_filter_fun' );


//Loop Counter
add_shortcode('incrementor', 'incrementor');
function incrementor() {
	static $i = 1;
	return $i++;
}

2. Register both shortcodes first ‘get_selected_filter’ and ‘incrementor’ in Toolset >> Settings >> Front-end Content >> Third-party shortcode arguments.

3. Then you can use these shortcodes in the View like this (its recommend to use in “Templates for this View” section since you are using ajax):

 
[wpv-conditional if="( '[incrementor]' eq '1' )"]
       [get_selected_filter taxonomy="bedcategory"] 
       [get_selected_filter taxonomy="gender"] 
[/wpv-conditional]

==> Whereas “bedcategory” is the taxonomy name.

This will display selected Terms on the page. Thanks

#561272

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

UPDATE: I have now slightly updated the php code in my last response.

#561408

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Sure thing, give it a try and let us know 🙂 Have a great weekend.

[ changing ticket status as: Waiting ]

Thank you

#562040

this was very helpfull thank you, however ending up not working for me as it needed to go inside the loop and I had to wrap it in a div I would have ended up with a lot of extra divs also I need to know what is selected when no results show up. I ending up using a JS version that seams to work for me updating on search updated.

jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {

      var radios = document.querySelectorAll('input[type="radio"][name="radio-name"]:checked');
var value = radios.length>0? radios[0].value: null;
// do something
  });