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
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
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.
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.
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
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.
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
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!
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.
Luo, thanks very much ! I will reopen a thread for my issues. Thanks.