This support ticket is created vor 3 Jahren, 10 Monaten. 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.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
i have a view and i want to show the "no items found" output with a condition.
The condition should be:
When loop items are smaller than 1 show the no items found if bigger than one item hide it.
This view is nested in another view therefore it could happen that in the parent view output has a lot of no items found between the loop items.
Or do you have another idea how this could be achieved?
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
loop items
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
/*only show this when loop items are smaller than 1*/
<strong>[wpml-string context="wpv-views"]No posts found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
I don't really understand what you mean, perhaps you could clarify.
A View queries wp_posts for posts, and it either finds some (there are some posts to loop over, at least one) or it doesn't (no items to loop over).
The condition you describe seems entirely redundant. If there are no posts found, that leaves us in the no-items-found section, where the number of loop items will always be zero and therefore smaller than one.
Your use case involves nesting Views, where you have a parent View, and in the loop section of the parent View you insert a child View. If the parent View returns no results then the child View will never be shown because there is no parent post to loop over.
If the child View returns no results, then whatever is in the no-results-found section will be shown. I can imagine that you might have several iterations where a parent post has no children, then the next parent post in the loop has no children, and then next... so that you end up with "No items found" being displayed by the child View 3 times in a row. Is that the problem? In that case you can simply output nothing at all in the no-items-found section of the child View. It is probably impractical in terms of the queries you would be generating to have the child View output the text "No items found" but a maximum of once.
"A View queries wp_posts for posts, and it either finds some (there are some posts to loop over, at least one) or it doesn't (no items to loop over)." Yes and i want to show or hide the no items with a conditional shortcode.
The nested child view shows all channelposts (child CPT) which are related to a channel (parent CPT). The Parent view takes care of all channels related to another parent. therefore i get all channelposts of all channels for that parent. As you mentioned i also get (screenshot) the "no post" between the loop because not all channels do have channelposts.
Therefore i would like to use a conditional shortcode to filter out these "no post" in between. But i do need the "no post" to be shown, when there is no channelposts at all.
So i want to wrap the loop item in conditional shortcode to filter out all items with the value of "no post" when the loop has at least one channelpost found.
Puh i hope this makes sense for you 😉 Quit complicated to explain.