Skip Navigation

[Resolved] Divi and table template with conditional if not working

This support ticket is created 5 years, 10 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 9 replies, has 3 voices.

Last updated by Shane 5 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#1216780

I am trying to:
Adding conditional if by checking that the email address i have in my cpt field matches that of the user logged in.
It should only show those records which match the email address.
Also if i take out the conditional if and allow the system to show all records , I get a 2 by 2 listing on my page.
When i add the conditional if i get a single row listing .

Link to a page where the issue can be seen:

I expected to see:
I expect to see a 2 columns listing only showing the record relating to the user logged in matching the email address

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->

<table width="100%" class="wpv-loop js-wpv-loop">
<wpv-loop wrap="2" pad="true">

[wpv-item index=1]
[wpv-conditional if="( $(wpcf-consultant-email) eq '[wpv-current-user info='email']' )"]
<tr>
<td>
[wpv-post-body view_template="loop-item-in-grid-planner-list-view-v4"]
</td>
[wpv-item index=2]
[wpv-conditional if="( $(wpcf-consultant-email) eq '[wpv-current-user info='email']' )"]
<td>
[wpv-post-body view_template="loop-item-in-grid-planner-list-view-v4"]
</td>

</tr>
<tr>
[/wpv-conditional]
[wpv-item index=pad]
<td></td>
[wpv-item index=pad-last]
<td></td>
</tr>
</wpv-loop>
</table>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

So if i take the conditional if out the record display in 2 columns , but i have no filter.
With the conditional if i get a single column but filter does still not work as expected.

#1217299

Hi, I don't recommend using conditionals in a View's loop for this reason - they can cause unexpected loop design problems. That's because conditionals are evaluated after the View's results are determined, which means the loop will then "skip over" some expected results that are hidden by conditionals.

Instead I recommend you add a custom field filter in the Query Filter section of this View. If you cannot see the Query Filter panel, scroll to the top right corner of the View editor screen and click "Screen Options". You can enable the Query Filter here. Add a new filter using the consultant email field, and set it to be equal to a shortcode attribute "email". Now you can pass the current User's email into the View as a shortcode argument. Find the shortcode used to insert this View, and add the current User's email using the wpv-current-user shortcode. Like this:

[wpv-view name="Your View Title" email="[wpv-current-user info='email']"]

Now you can remove all the conditionals from your loop, since the results are now filtered automatically. This technique is called passing arguments to Views: https://toolset.com/documentation/user-guides/passing-arguments-to-views/

#1217885

My issue is resolved now. Thank you!

#1217899
grid display mobile.JPG
grid display1.JPG

Hi
I have another question related to the same project.
I am using DIVI for the layout , using toolset grid.
See uploaded image
grid display 1 .. Why are the columns not the same size ?
grid display mobile .. What is the best why using div to get it to switch to stacking on mobile ?

Thanks
Tony

New threads created by Christian Cox and linked to this one are listed below:

https://toolset.com/forums/topic/layout-issues-with-grid-view-and-divi/

#1217976

Okay I have split your question about the grid layout into a separate ticket so we can discuss in more detail. Our policy is one topic per ticket, which helps keep things organized. I'll follow up in the other ticket shortly.

#1232276

Hi Christian

One thing that has come up relating to this
[wpv-view name="Your View Title" email="[wpv-current-user info='email']"]

On the page I have added this it works well if the user is logged in, but if the user is not logged and goes to that page it shows all the records

hidden link

I need to prevent it from doing that, meaning if it does not have a wpv-current-user info='email' value we should not get anything.

Thanks
Tony

#1232288

I have done it this , is that ok or do you have a better way

Select items with field:
Consultant Email is a string equal to VIEW_PARAM(email)
OR
ConsultantEmail is a string not like

Tony

#1232371

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mike,

As Christian is currently unavailable, I will be handling this ticket for him.

You should actually be able to achieve this by using some conditional code Example


[wpv-conditional if="( [wpv-current-user info='email']  ne ' ' )"]

[wpv-view name="Your View Title" email="[wpv-current-user info='email']"]

[/wpv-conditional]

So what should happen is that the view does not get rendered unless a value is detected for the email.

Thanks,
Shane

#1232653

Hi Shane
I think what you sent me had a couple of syntax errors, as it was not working.
Who is this - conditional if : [wpv-current-user info='email']

[wpv-conditional if="( '[wpv-current-user info='email']' ne '' )"]

[wpv-view name="tony-test" email="[wpv-current-user info='email']"]

[/wpv-conditional]

This issue was round the [wpv-conditional if="( [wpv-current-user info='email'] ne ' ' )"]
I changed that to : wpv-conditional if="( '[wpv-current-user info='email']' ne '' )"]

Hope that is right.

Thanks
Tony

#1232882

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Tony,

Yes this should be correct now based on our documentation here.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/#checking-for-the-current-user-data

Are you getting the desired output ? Does the view show up if the condition is met?

Please let me know.

Thanks,
Shane