Skip Navigation

[Resolved] Compare user field values in Gutenberg Toolset Conditional block

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user was unable to perform some checks between the current user fields, default fields, and custom fields.

Solution:
Use the wpv-user shortcode instead of types shortcode. Check this example:

( ( '[wpv-search-term param="_success"]' != '' ) AND
( ( '[types usermeta="1-1-new-first-name" output="raw" current_user="true"][/types]' = '[wpv-user field="user_firstname"]' ) OR
( '[types usermeta="1-1-new-last-name" output="raw" current_user="true"][/types]' = '[wpv-user field="user_lastname"]' ) ) )

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-154505

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 4 replies, has 2 voices.

Last updated by GamX 4 years, 3 months ago.

Assisted by: Jamal.

Author
Posts
#1821497

Hello, using the Gutenberg Toolset Conditional block, what is the correct syntax for a condition that compares field values between a WordPress user field and a Toolset custom user field?

I created two Toolset custom user fields:
1-1-new-first-name
1-1-new-last-name

I created a Toolset user form: 1-1-new-name-form
This form includes the above two fields.

I display that form when the user first visits the page, which I determine by a Toolset Conditional block:
( ( '[wpv-search-term param="_success"]' = '' ) )

After the user submits this form, I want a second Toolset conditional block to show additional content IF either:
(wordpress user first name = 1-1-new-first-name) OR (wordpress user last name = 1-1-new-last-name)

TOOLSET CONDITIONAL BLOCK THAT NEEDS CORRECTION
( ( '[wpv-search-term param="_success"]' != '' ) AND
( ( '[types usermeta="1-1-new-first-name" output="raw" current_user="true"][/types]' = 'user_firstname' ) OR
( '[types usermeta="1-1-new-last-name" output="raw" current_user="true"][/types]' = 'user_lastname' ) ) )

Thank you!

#1822679

Hello and thank you for contacting the Toolset support.

WordPress default user fields(first and last names) are stored in the "usermeta" table the same way Toolset fields are stored, and you can get their values with the same shortcodes. They are called, respectively, "first_name" and "last_name".
Please try this code:

( ( '[wpv-search-term param="_success"]' != '' ) AND
( ( '[types usermeta="1-1-new-first-name" output="raw" current_user="true"][/types]' = '[types usermeta="first_name" output="raw" current_user="true"][/types]' ) OR
( '[types usermeta="1-1-new-last-name" output="raw" current_user="true"][/types]' = '[types usermeta="last_name" output="raw" current_user="true"][/types]' ) ) )

I hope this helps. Let me know what you will get.

#1825395

Thanks Jamal, I tried the code but it doesn't seem to work. The user's first_name is Emily, but when I enter Emily as the 1-1-new-first-name, the condition does not show as true.

I even did a simpler test where the conditional block statement was the following, but this did NOT test true when it should have:
( '[types usermeta="1-1-new-first-name" output="raw" current_user="true"][/types]' = '[types usermeta="first_name" output="raw" current_user="true"][/types]' )

And the following also did NOT test true when it should have:
( '[types usermeta="first_name" output="raw" current_user="true"][/types]' = 'Emily' )

Conversely, this statement tested true correctly:
( '[types usermeta="1-1-new-first-name" output="raw" current_user="true"][/types]' = 'Emily' )

Is there something wrong with the way I'm referring to the wordpress first_name field?

#1826023

I run a small test and I also was not able to get the default field(first_name) using the types shortcode. I was able to get it using the wpv-user shortcode.
Please check if the following code helps:

( ( '[wpv-search-term param="_success"]' != '' ) AND
( ( '[types usermeta="1-1-new-first-name" output="raw" current_user="true"][/types]' = '[wpv-user field="user_firstname"]' ) OR
( '[types usermeta="1-1-new-last-name" output="raw" current_user="true"][/types]' = '[wpv-user field="user_lastname"]' ) ) )

Read more about the shortcode here https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-154505

#1826201

Thank you! This worked, although I had to get rid of the line breaks which I like for readability, but apparently they don't work inside Gutenberg blocks.