Skip Navigation

[Resolved] Conditional based on user meta URL field doesn't work

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

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 9 replies, has 3 voices.

Last updated by Jamal 4 years, 3 months ago.

Assisted by: Jamal.

Author
Posts
#1757173

There seems to be a bug where a conditional in a View content template will not work correctly if the conditional is evaluating whether a user field of type URL is empty or not.

I am trying to: Add fields to the users for various social media, and display an icon on the front end only if the field is not empty.

I expected to see: The icon show or hide based on whether or not the condition evaluates to true or false i.e. a URL was in the URL field (e.g. hidden link).

Instead, I got: No icon or link shows whether the condition evaluates to true or false. I changed the field type from URL to Single Line and the conditional logic works as expected.

#1757631

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

First of all - After checking to debug the information you shared with us, I found that you are using outdated Toolset plugins. We always recommend running your site with the latest stable release plugin version.

*** Please make a FULL BACKUP of your database and website.***
Could you please update ALL Toolset plugins to it's latest officially released version. You can download the latest plugin release from your accounts page:
=> https://toolset.com/account/downloads/

Once you update ALL Toolset plugins to official latest stable release version. Can you please check if you still having the same issue? if yes:
- I would like to review how you added conditional statement to your site.

Can you please share problem URL and access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1758325

While setting up a demo, I stumbled upon the solution to the problem.

When writing a conditional with user meta fields type URL, the field for evaluation must include

output='raw'

.

For example, this will not return any results, whether the field is used or not:

[wpv-conditional if="('[types usermeta='twitter'][/types]' ne '' )"]
    [types usermeta='twitter'][/types]
[/wpv-conditional]

This however works as expected. Note output='raw' on the usermeta field in the if statement:

[wpv-conditional if="('[types usermeta='twitter' output='raw'][/types]' ne '' )"]
 [types usermeta='twitter'][/types]
[/wpv-conditional]
#1758339

I submitted this as a bug report. If this isn't a bug, I'd like to re-submit it as a support request so that it will be archived in the forum. Let me know how I should do that. Thank you!

#1758651

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

This is not a bug. As you can see with the Doc the default output mode for the URL field is "normal" that is wrapped with html.
=> https://toolset.com/documentation/customizing-sites-using-php/functions/#url

So, you will require to use the output="raw" to get the value that is saved to database.

#1761759

This isn't about the output. It's about the conditional evaluating whether or not the field is empty.

Outputting the field value (as a link or as txt) was never a problem, but having the conditional evaluate whether or not the field even has a value simply doesn't work on user meta URL fields without adding "output='raw'" to the field being evaluated in the conditional.

That is not how it works on post fields. On post fields, a URL field can be evaluated in a conditional as-is.

#1763181

Hello, as Minesh is on vacation, I'll continue with you on this ticket. I hope that's fine.

From what I understand so far, you expect a condition evaluation on a URL user field to match without using the "raw" parameter, right?
Or, if I understood well, you expect the following shortcode to return an empty string if the field is empty, right?

[types usermeta='twitter'][/types]

To be able to escalate this issue to our 2nd Tier for another analysis before being handled by a developer, we'll need to reproduce it on a clean installation on our platform, for that reason, I created a new WordPress site and I hope you will help reproduce the issue on it. You can log into it with the following URL hidden link

Once the issue is reproduced, I'll escalate it to our 2nd Tier and I'll keep you updated on its progress.

Thank you for your collaboration.

#1763609

Hi Jamal,

Thank you for the sandbox site. That's very helpful. I've created a demo that shows the issue: hidden link

This demo consists of custom user fields, a View to loop through the users (only one user in the demo) and display those fields only if they have values entered, and a custom post field added for comparison.

#1764269

Thank you for your collaboration.

Let me approach our 2nd Tier for another opinion on this and get back to you.

#1774147

Our developers are taking this issue into consideration and will work on it in the future.

As the workaround of using output="raw" is working for this case, I'll have to kindly ask you to mark this ticket as resolved.

Thank you for reporting this issue.