Skip Navigation

[Gelöst] View: control the [wpv-no-items-found] with a condition

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:

I have a view and I want to show the "no items found" output with a conditione:

When loop items are smaller than 1 show the no items found if bigger than one item hide it.

Solution:

You can use shortcode [wpv-found-count] to get view's result count for example:

https://toolset.com/forums/topic/view-control-the-wpv-no-items-found-with-a-condition/#post-1884803

Relevant Documentation:

https://toolset.com/forums/topic/view-control-the-wpv-no-items-found-with-a-condition/#post-1884803

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.

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)

Dieses Thema enthält 4 Antworten, hat 3 Stimmen.

Zuletzt aktualisiert von SteffenM1628 vor 3 Jahren, 10 Monaten.

Assistiert von: Luo Yang.

Author
Artikel
#1883673

Tell us what you are trying to do?
Hey there,

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]

Thanks

#1884087

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

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

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.

#1884139
Bildschirmfoto 2020-12-22 um 16.47.30.png

Hey Nigel thanks for your reply.

"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.

#1884803

Hello,

If there isn't any result, Views will output "No item found".
If there is results, Views will not output "No item found".

And you can use shortcode [wpv-found-count] to get view's result count:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-155378

Use above shortcode in wpv-conditional shortcode, compare it with number 1, and output what you want, for example:

[wpv-conditional if="( '[wpv-found-count]' eq '1' )"]
Only one item
[/wpv-conditional]

More help:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-conditional

#1887029

My issue is resolved now. Thank you!