Skip Navigation

[Closed] Conditional Block not working with Views Condition: Number of Items Displayed

This support ticket is created 3 years, 9 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.

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 3 years, 9 months ago.

Author
Posts
#2134047
Gift a Creator - Front End - Conditional 1 with 1 post.PNG
Gift a Creator - Conditional attempt 1.PNG
Gift a Creator - Condition Attempt 1 Edit Screen - Annotated.PNG
Basic Gift Vw - Settings - Loop Editor - screenshot 3.PNG

I am trying to:
Conditionally display content based on whether a user has submitted a post of the "Basic Gift" post type.

The end goal is to have a conditional block that displays a Forminator post creation form (of the "Basic Gift" post type) if the user has not already created a post of that type. I created a conditional block containing the Forminator form and a toolset view. When I couldn't get the conditional block to work correctly, I took the Forminator form out and replaced it with paragraph text to assist with debugging the issue

The View I'm using is called "Basic Gift Vw". It displays posts of the "Basic Gifts" post type, where the author is the same as the as the current logged-in user. Following the advice from a similar Toolset issue thread, I created the following code in the Loop Editor:

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-items-count]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpv-found-count]
[/wpv-no-items-found]
[wpv-layout-end]

When this View is displayed in a page, it displays the number of Basic Gift posts a user has created.

Then, in the page where this View is used, I created a Conditional block with the following logic:

NOT ( ( '[wpv-items-count ]' gte '1' ) )

Inside of this block is the "Basic Gift Vw" and paragraph text that says: "This SHOULD show if the number of items displayed in the view loop is 0. This should NOT show if the number of items displayed in the view loop is > 0."

Theoretically, on the front end this should show the number of posts a user has created (0), followed by the aforementioned text, IF there are no posts found in the view. Otherwise, nothing should be displayed.

Instead, the number of posts and the paragraph text is displaying, regardless of if the current user has 0 or 1 Basic Gift posts.

Attempt 2:
I changed the Conditional logic to: ( ( '[wpv-items-count ]' gte '1' ) )
This results in the block NOT displaying, regardless of if the current user has 0 or 1 Basic Gift posts.

Attempt 3:
I changed the Conditional logic to: NOT ( ( '[wpv-items-count ]' gt '0' ) )
This results in the block displaying, regardless of if the current user has 0 or 1 Basic Gift posts.

Additional Attempts:
I tried adding the condition: Views Shortcode: Archive Title = Static Value: "basic-gift-vw"
( ( '[wpv-items-count ]' lt '1' ) AND ( '[wpv-archive-title ]' eq 'basic-gift-vw' ) )
Which did not work either.

*Note: I am NOT a programmer, which is why I bought Toolset for my website. That being said, I can follow basic and clear instructions to copy/paste code, insert the proper slugs, etc.

Link to a page where the issue can be seen:
hidden link

I expected to see:
Content displayed depending on if a user has 0 Basic Gift posts or >0 Basic Gift Posts.

Instead, I got:
Content displays regardless of if a user has 0 Basic Gift posts or >0 Basic Gift Posts.

#2134553

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

If you have a View to display posts authored by the current user, it will iterate over their posts in the loop output section, or typically display a message such as "No items found" when there are no such posts.

Rather than trying to use this View in a condition, you can just output what you want directly in the View itself.

If there is a post, you can output whatever makes sense, e.g. the post title.

If there is no post, then you can replace the No items found text with your form (I assume you can insert the form using a shortcode).

In your screenshots, presumably based on what you've read in other threads, you have worked with a View using the legacy editor. You can still do that, and insert the shortcode for the form in the wpv-no-items-found section.

Or if you are more comfortable using the block editor for your Views, you can select the View Loop block and then in the sidebar settings you'll find where the No Items Found Text is set under the Loop Template option. Replace the text with the shortcode for your Forminator form.

The topic ‘[Closed] Conditional Block not working with Views Condition: Number of Items Displayed’ is closed to new replies.