Skip Navigation

[Resolved] how to check whether a taxonomy term has published posts?

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

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/Hong_Kong (GMT+08:00)

This topic contains 9 replies, has 2 voices.

Last updated by williamm-5 6 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#557985

Tell us what you are trying to do?

I wan to conditional display taxonomy terms based on whether it has published posts. The result should be display in the view.

Is there any documentation that you are following?

by view

Is there a similar example that we can see?

hidden link

What is the link to your site?

no

#557989
empty-terms.JPG

Dear Williamm,

There isn't such a feature within Types plugin.

But if you have a copy of Views plugin
https://toolset.com/home/views-create-elegant-displays-for-your-content/
you can use shortcode [wpv-taxonomy-post-count] to get the the number of posts for the current taxonomy:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-taxonomy-post-count

Then you can use it insider the [wpv-conditional] shortcode to display what you want depends on the result of [wpv-taxonomy-post-count], see our document:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

If you want to display terms which are assigned to posts, you can create a taxonomy view, with option:
Don't show empty terms
see screenshot empty-terms.JPG

You can also built the query with PHP codes manually, see wordpress document:
https://developer.wordpress.org/reference/classes/wp_term_query/__construct/
parameter:
'hide_empty'
(bool|int) Whether to hide terms not assigned to any posts. Accepts 1|true or 0|false. Default 1|true

#557995
the result2 .jpg
the result1 .jpg
display post view.jpg
display taxonomy view.jpg

Dear Luo,

Thanks very much for your quick response.

Still need you help, and I don't know how to use toolset to conditional display as you told as your mention below:

<If you want to display terms which are assigned to posts, you can create a taxonomy view, with option:
Don't show empty terms
see screenshot empty-terms.JPG>

following attached are my setting and it shows nothing.

1. result1.jpg is showing the result which is "display post view.jpg" sort by field child post count.
2. result2 .jpg is showing the result which is "display post view.jpg" sort by child post id.

actually, this is no post under "医药品" term.

waiting for your instruction. Thanks.

#558003

Luo, sorry

you have already answer my question perfect. Thanks.

Actually, my question is not been asking in the right way.

There is a child post link to parent post which has taxonomy.

I want to know how to check whether a taxonomy term has published child posts?

thanks and sorry for misleading.

#558019

In your screenshot:
hidden link
The taxonomy view, you have already enabled the option "Don't show empty terms", so it should not output those term which do not have any posts assigned,

The problem you mentioned above is abnormal, we need to check if there is any compatibility problem in your website, I suggest you try this:
1) Make sure you are using the latest version of Types + Views plugin
2) deactivate other plugins and switch to wordpress default theme, and test again
3) If the problem still exists, please provide downloadable URL for the database dump file of your website in below "private detail box", also point out the problem page URL and view URL, where and how I can see the problem, I need to duplicate same problem and debug it in my localhost, thanks

#558033

Dear Luo,

This is no problem with toolset types plugin.

I try to use following code to check the view return result. But it is not work.

[wpv-conditional if="( '[wpv-view name="sidebar-product-market-detail"]' ne 'No items found' )"]
<h3>[wpv-taxonomy-title]([wpv-taxonomy-post-count])</h3>
<div>[wpv-view name="sidebar-product-market-detail"]</div>
[/wpv-conditional]

how could i get the return result from the view [wpv-view name="sidebar-product-market-detail"] in the view design panel.

Thanks.

#558050

Views will output results in a HTML div tag, if there is any result, it will output something like this:

<div class="xxx">
No items found
</div>

If ther
So the shortcode [wpv-conditional] you mentioned above won't be able to work.

As I mentioned above:
you have already enabled the option "Don't show empty terms", so it should not output those term which do not have any posts assigned, but it does not work in your website, it is abnormal, we need to check if there is any compatibility problem in your website, I suggest you try this:
1) Make sure you are using the latest version of Types + Views plugin
2) deactivate other plugins and switch to wordpress default theme, and test again
3) If the problem still exists, please provide downloadable URL for the database dump file of your website in below "private detail box", also point out the problem page URL and view URL, where and how I can see the problem, I need to duplicate same problem and debug it in my localhost, thanks

#558051

Thanks Luo,

As you said: Views will output results in a HTML div tag.

Can we just let Views output raw.

For example:
just output "No items found"

rather than

<div class="xxx">
No items found
</div>

thanks in advance!

#558060

No there isn't such a built-in feature within Views plugin, Views is not a data provider, it is not recommended to use view's shortcode insider the [wpv-conditional].
I suggest you move the taxonomy shortcode and post count shortcode insider the view "sidebar-product-market-detail", section "Loop Output Editor", wrap them into shortcode [wpv-items-found] ... [/wpv-items-found], see our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-items-found
wpv-items-found
Meta HTML wrapped in [wpv-items-found][/wpv-items-found] will be output if there are any posts | taxonomies | users returned by the View.

#558067

Luo, thanks very much ! I will reopen a thread for my issues. Thanks.

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.