Skip Navigation

[Resolved] [wpv-post-taxonomy] not working with wpv-conditional

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

Problem:
Would like to hide taxonomy Terms that do not have any posts attached to it.

Solution:
You can do that using Custom Search Settings >> Show only available options for each input.
Screenshot here:
https://toolset.com/wp-content/uploads/2017/09/572544-Show_only_available_options_for_each_input.png?x62720

This support ticket is created 7 years, 2 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 11 replies, has 2 voices.

Last updated by marcB-6 7 years, 2 months ago.

Assisted by: Noman.

Author
Posts
#572146
Screenshot_22.png

I am trying to hide filter toggle if particular taxonomy does not have any terms.

I have put below condition :

[wpv-conditional if="([wpv-post-taxonomy type='document-type' format='slug'] ne '' )"]
<div class="form-group">
 <label class="active">[wpml-string context="wpv-views"]Document types[/wpml-string]</label>
 <div class="checkbox-grp">[wpv-control-post-taxonomy taxonomy="document-type" type="checkboxes" url_param="wpv-document-type" format="%%NAME%%<span>(%%COUNT%%)</span>" hide_empty="true"]</div>
</div>
 [/wpv-conditional]

but it is not working..please check screenshot

Thanks

#572152

Noman
Supporter

Languages: English (English )

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

Hi Marc,

Thank you for contacting Toolset support. Looks like there is a mistake in the conditional syntax, apostrophes are missing. The correct syntax is:

[wpv-conditional if="('[wpv-post-taxonomy type='foreign-language' format='slug' ]' ne '' )"]
Your content here...
[/wpv-conditional]

Doc: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/

And your updated code would be like this:

[wpv-conditional if="('[wpv-post-taxonomy type='document-type' format='slug' ]' ne '' )"]
<div class="form-group">
 <label class="active">[wpml-string context="wpv-views"]Document types[/wpml-string]</label>
 <div class="checkbox-grp">[wpv-control-post-taxonomy taxonomy="document-type" type="checkboxes" url_param="wpv-document-type" format="%%NAME%%<span>(%%COUNT%%)</span>" hide_empty="true"]</div>
</div>
 [/wpv-conditional]

I hope it helps, thank you

#572402

Hi Noman,

As you can see in above screenshot I have given..."Document Type" toggle has terms "studies","surveys", so as per condition you gave above it says if type='document-type' not equal to blank then show toggle..but I have terms for "Document Type" so it should not hide it..

I have put above condition and it hides my toggle..which it should not as it is having terms

Thanks

#572544

Noman
Supporter

Languages: English (English )

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

Show only available options for each input.png

Hello Marc,

So you would like to hide Terms that do not have any posts attached to it, is that correct?

If yes, you can do that using Custom Search Settings >> Show only available options for each input. Without any conditional -- see attached screenshot.

Thank you

#572598
Screenshot_23.png
Screenshot_24.png

Hi Noman,

Custom Search Settings >> AJAX results update when visitors change any filter values -- This is my current option selected
I have checkbox filters + count for each term + total results in my page + Infinite scrolling..which changes value based on filter value selection.

So If I apply Custom Search Settings >> Show only available options for each input..It is not working as it is working with my current settings mentioned above.

see attached screenshot for page and settings.

Thanks

#572654

Noman
Supporter

Languages: English (English )

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

Custom search settings.png

- Can you please update your search settings as in attached screenshot and then let us know if you still found any issue. The settings that we have in the 4th radio option, is also available in the 5th radio option, as I have shown in my screenshot, please set all these options exactly as I have setup in my attached screenshot.

- Have you applied any custom code using hook or some other way to this View or page?

If above does not solve the issue, please provide temporary access (WP-Admin and FTP Login info) to your site (preferably staging site), so that I can look into your setup and check the issue.

Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please provide the Page link, View Edit Screen link, Taxonomy backend link as well.

Thank you

#572800
Screenshot_25.png

Hi Noman,

I have applied the same setting as you mentioned above but when I click filter checkboxes after infinite scroll it is not working..

- Have you applied any custom code using hook or some other way to this View or page?
Answer : No

This reply is not private...you forget to make it private so I am can not provide you details..make it private first

Thanks

#573160

Noman
Supporter

Languages: English (English )

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

Private message box is enabled now.

#573270

Noman
Supporter

Languages: English (English )

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

Hello Marc,

Thanks for sending login. I've added following JS code in View's >> JS editor scectin, for removing empty taxonomy div and now it's working as required:
hidden link

function taxonomy_term_func() {
	$(document).find('.checkbox-grp').each(function(index, element) {
		if($(this).html().trim().length == 0) {
			$(this).parents('.form-group').remove();
		}
	});
}

taxonomy_term_func();

jQuery( document ).on( 'js_event_wpv_pagination_completed', function( event, data ) {
  taxonomy_term_func();
});

Thank you

#573512

Hi Noman,

Will this work for all taxonomies mentioned in page : hidden link
I mean Document Type, Meetings , Subjects , Committees or may be more in future..

Note : Christian Cox is working on same page for this ticket : https://toolset.com/forums/topic/add-custom-option-in-sorting-controls-dropdown/#post-573514. so, please do accordingly and make sure it doesn't break anything..

Thanks

#573558

Noman
Supporter

Languages: English (English )

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

Hello Marc,

Yes, it will work on this page with existing taxonomies as well as new taxonomies.

I am not working on this page and your site now, you can please kindly mark this current ticket as resolved if all is good now.

Have a great day.
Thank you

#573587

Ok Thanks!!