Skip Navigation

[Gelöst] Conditional block. Only show the block if the view inside it returns any records

This support ticket is created vor 1 Jahr, 6 Monate. 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.

This topic contains 1 Antwort, has 2 Stimmen.

Last updated by Jamal vor 1 Jahr, 6 Monate.

Assigned support staff: Jamal.


Hello Support

I have created two custom post types.


One Lesson can have multiple downloads
One download can be related to multiple lessons.

So I have created a Many to Many relationsship between lesson and downloads.

I am building the lesson content template.

In the lesson content template I want to display a block with a view of the related downloads, but ONLY if there are any related downloads to the lesson.

There is no point ins showing a Title "Lesson downloads" if there are no lessons to display.

So how do you build a conditional Gutenberg block where the condition is, "are there any records returned by the query"?




Languages: Englisch (English ) Französisch (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting the Toolset support.

There is currently no way to calculate the count of results of a view outside of the view(in the wrapper conditional block). So, you will have to create a custom function that calculates the count, register it in Toolset settings, then use it inside the conditional block.

In this custom function you can either use:
- The toolset_get_related_posts function from our relationship api
- Or the get_view_query_results from our views api
Both functions will return an array of results, you can check if it is empty using the empty php function. Maybe this thread may help.

I hope this helps. Let me know if you have any questions.