Skip Navigation

[Resolved] Conditional if author user field is empty

This support ticket is created 6 years, 6 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 13 replies, has 2 voices.

Last updated by Ian 6 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#872563

Ian

I have a user field called phone. I want to be able to determine if that field is empty for the author of the current post.

I currently have this:

[wpv-conditional if="( '[wpv-user field='wpcf-phone']' ne '' )"]
my content
[/wpv-conditional]

#872875

Shane
Supporter

Languages: English (English )

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

Hi Ian,

Thank you for contacting our support forum.

You can try this code below.


[wpv-conditional if="( '[wpv-user field='wpcf-phone' id='[wpv-post-author meta='ID']']' ne '' )"]
my content
[/wpv-conditional]

PLease that and let me know if it helps.

Thanks,
Shane

#873016

Ian

The phone field is filled out and there should be an icon showing up before it but nothing is showing up. Here is my code

<div class="vendor-profile">
[wpv-conditional if="('[wpv-user field='wpcf-phone' id='[wpv-post-author meta='ID']']' ne '' )"]
 <div class="vendor-icon"><i class="fas fa-phone fa-lg" title="Vendor Phone Number"></i></div>
[/wpv-conditional]

<div class="vendor-phone">[types usermeta="phone" user_is_author="true"][/types]</div>
</div>
#873645

Shane
Supporter

Languages: English (English )

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

Hi Ian,

Would you mind providing me with a link to this page so that I can have a look ?

The private fields have been enabled for your next response.

Thanks,
Shane

#876858

Shane
Supporter

Languages: English (English )

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

Hi Ian,

It should now be working.

The correct shortcode shouldve been [types usermeta="phone"][/types]

Thanks,
Shane

#889915

Ian

OK something a little more complex. This is not showing up even when the field is filled out. The link works correctly without the conditional statement.

[wpv-conditional if="('[types usermeta="facebook-url"][/types]' ne '' )"]<a class="vendor-link vendor-facebook" href="[types usermeta='facebook-url' output='raw' user_is_author='true'][/types]" target="_blank" ><i class="fab fa-facebook-square fa-2x" title="Facebook"></i></a>[/wpv-conditional]
#894572

Shane
Supporter

Languages: English (English )

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

Hi Ian,

It seems that the conditionals are not working at all with the user field.

Would it be possible if I got a local copy of your site to test this further ?

Thanks,
Shane

#894574

Ian

I can do that. I could package it with Backup Buddy.

#901692

Shane
Supporter

Languages: English (English )

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

Hi Ian,

Sorry for the delay in response, but I could install the duplicator plugin and create the backup using that to test locally.

Please let me know if I can.

Thanks,
Shane

#901768

Ian

Sure no problem.

#902071

Shane
Supporter

Languages: English (English )

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

Hi Ian,

I was able to find the issue.

It seems it was the way you formatted the conditional shortcodes and a qoute was missing.

Could you use this as this should work.


[wpv-conditional if="( '[wpv-post-author format='meta' meta='wpcf-facebook-url']' ne '' )" debug="true"]<a class="vendor-link vendor-facebook" href="[types usermeta='facebook-url' output='raw' user_is_author='true'][/types]" target="_blank" ><i class="fab fa-facebook-square fa-2x" title="Facebook"></i></a>[/wpv-conditional]

Also could you use this as an example going forward so that the conditionals work correctly.

Thanks,
Shane

#906278

Ian
conditional.jpg

Shane,

I implemented the shortcodes as you suggested and it is still not working. In fact none of my conditional statements are working, including the ones that were working previously.

  • The phone icon that should be showing up before the phone number is not working
  • The email and facebook links are not showing up below the phone number
  • The product listing that was working before under products is not working either

Not sure why some stuff has quit working

#906335

Ian

It would appear that shortcodes need to be inserted into DIVI text modules and not DIVI code modules. This is unfortunate as then some CSS specific to text modules need to be overriden.

#906862

Ian

One additional note, it would be great if it could be determined why this is not working in the code module. The text module adds auto paragraphs so you can not leave your code nicely formatted making editing much harder.