Skip Navigation

[Resolved] Don't show empty terms

This support ticket is created 6 years, 1 month 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

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

This topic contains 11 replies, has 3 voices.

Last updated by winyS 6 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#1156163

I am trying to display a list of terms (countries) with the posts that have that term (experts), both in alphabetical order.

I use a nested view and followed this threads.

https://toolset.com/forums/topic/taxonomy-views-dont-show-empty-terms-not-quite-right/
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/

Example here: hidden link (only for logged in members so I attach a screenshot)

As you can see the empty terms are in the list. Displayed are the term name and the text "No items found".
Is it possible only to show the terms that are not empty?
In Query Options I checked "Don't show empty terms".

#1156267

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

I just tested this, and it seems to be working correctly on my own site.

You are using nested Views, right? And the outer View queries the taxonomy terms, and has the option "Don't show empty terms" checked.

What about the option "Include terms that have non-empty descendants"? Do your country terms have child terms that may be assigned to posts?

#1156339
Schermafdruk 2018-11-30 14.50.32.png

Hi Nigel,
Thanks for your answer.
I hace this option checked as well, in the outer view.
View screenshot.

The "empty" terms do have posts, not Experts but Rescue stations.
Could this be the problem?

#1156399

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Yes, that would be the issue.

Your inner, nested, View is only displaying Experts, but the outer View doesn't know that it should only consider expert posts for the term count that determines whether a term is empty or not.

The underlying term query argument for 'hide_empty' is a simple boolean, it is either on or off, and can't be modified to specify which post types should be counted (https://developer.wordpress.org/reference/classes/wp_term_query/__construct/#parameters), so I don't see a way around this.

Except you could use the Views API to add a function that loops over the terms—before they are returned—and test whether they actually have any expert posts assigned, and if not remove them from the results: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_post_query

#1158581

Thanks for your answer Nigel. I will give it a try this week.

#1158663

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

OK, good luck. Let me know how you get on.

#1159617

Hi Nigel,
I would like to try this.
But it seems very complicated for me as a non-coder.
What exactly should I write in the filter and in which of the views (and where) should I place it?
I hope you can help me further.
Thank you.

#1160040

Nigel, I think I found a simpler solution. Let me work on it for a while, I will let you know when the result is OK.

#1160482

Hi there,

Thanks for the update and glad you found a simpler solution.

Nigel is away for a few days and will be back early next week.

You're welcome to continue on this ticket around the same topic or open a new one for a different question/concern.

regards,
Waqar

#1163961

Hi Nigel,

I resolved the problem.
I created an archive for Experts with nested views as explained earlier in this thread.
I deleted the code between <wpv-loop> and </wpv-loop>.
I added a view above the loop that shows the Taxonomy "Countries" ordered by term name, ascending (=alphabetical):
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>

    [wpv-view name="list-experts-with-term-from-parent-view-2"]

</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

The nested view shows Experts, ordered by Post title (=Expert name), ascending (=alphabetical):
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<ul class="experts-in-country"><wpv-loop>

  • [wpv-post-link] ([wpv-post-taxonomy type="country-information"])<br>
    [types field='expert-phone-number'][/types]
  • </wpv-loop>

    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found]
    [wpml-string context="wpv-views"][/wpml-string]
    [/wpv-no-items-found]
    [wpv-layout-end]

    The reult is exactly what I wanted.
    See screenshot.

    Can you delete both screenshots of the web page after reading my solution, because they contain private information.

    #1164554

    Hi Winy,

    Thank you for sharing these details and I'm sure they'll prove useful for other users with a similar requirement.

    The two screenshots have been removed from the thread, as requested.

    You're welcome to mark this thread as resolved and open a new ticket for a different question.

    regards,
    Waqar

    #1164596

    My issue is resolved now. Thank you!