Skip Navigation

[Resolved] Conditionally hiding a header when View has no results

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to hide some header text displayed just above my View if the View contains no results.

Solution: In the Block editor it's not so simple, but in Classic Views you have the ability to add content in the wpv-items-found section just before the wpv-loop tags. This will display the header if the View has any results.

This support ticket is created 4 years, 8 months 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by BrandenT2154 4 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#1594327

I have a CPT called 'reps' each rep is a company, and each company has multiple contacts. So i created a repeatable field group called company contacts, and displayed it on the front end with a view.

just above the view I have a header that says 'Contact Somone' and i want this to conditionally hide if there are no contacts inputted into the repeatable field group. in other words i want the heading to hide conditionally if there is no data in the repeatable field group.

I see that i can use the 'fields and text' block to creation conditions, however i do not see the field group in the list of fields to make a condition from.

link to login: hidden link

link to content template: hidden link

#1594691

Hello, I see what you mean - you would need a way to set up a conditional to test the number of results in your View of the RFG. Unfortunately this isn't very simple to achieve in the Block Editor. If you're comfortable working with shortcodes, I can show you how to use Classic Views to achieve this type of conditional display. Let me know if that's something you would like to pursue.

#1594693

yes, comfortable with shortcodes and some php - just new to toolset. yes, please explain away!

#1595723

Okay if you go to Toolset > Settings > General you can enable the classic Views interface by choosing " Show both the legacy and Blocks interface and let me choose which to use for each item I build" in the Editing experience settings. That will give you access to a new Views menu item. Create a new View and choose your RFG as the Content Selection. Add a post relationship Query Filter so the View only shows those RFGs related to the post where this View is shown. Then use the Loop Wizard to build your design with the Block Editor if you'd like.

Once that is done, in the Loop Editor panel, you can add your header text just after the wpv-items-found block. This isn't possible in the Block Editor, but in the Classic Editor you can add content that will display if any results are found, but outside the loop. Once your View is complete, you can add it to your template using a Views block. Let me know if you have questions about this.

#1600917

My issue is resolved now. Thank you!