Skip Navigation

[Resolved] wpv-if not working with usermeta

This support ticket is created 7 years, 3 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 17 replies, has 3 voices.

Last updated by marcB-6 7 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#563852
Screenshot_15.png
Screenshot_14.png

I am checking value of usermeta field using below condition in to content template, but it is not working, not printing any data.

[wpv-if evaluate="'[types usermeta='_new_user'][/types]' = '0'"]value is 0[/wpv-if]

Please check screenshot for the database field.

Thanks

#563969

Hi, I think your logic looks fine and the if statement seems to be using the correct syntax...so something else must be going on. Can you answer these questions for me?
- I can't tell from the screenshots, are you logged in as the User with ID 11 when you test this? If not, how are you determining which User's information is being displayed?
- How is this Content Template applied to your site? Is this part of a View, or the Content Template for a single post type, or archive?
- Where are you testing the results - on a single post page, or an archive page, or a custom page?
- If you disable all plugins except Layouts, Types and Views, is the conditional working as expected?

#564105
Screenshot_16.png

Hi Christian Cox,

Please check answers to your questions below.

- I can't tell from the screenshots, are you logged in as the User with ID 11 when you test this? If not, how are you determining which User's information is being displayed?

ans : Yes, I am logged in as the User with ID 11.

- How is this Content Template applied to your site? Is this part of a View, or the Content Template for a single post type, or archive?

ans : I have created dashboard template using Toolset > Content Templates then I have created a page "dashboard" and applied that template to page.

- Where are you testing the results - on a single post page, or an archive page, or a custom page?

ans : custom dashboard page

- If you disable all plugins except Layouts, Types and Views, is the conditional working as expected?

ans : I have not installed Layouts plugin.

Thanks

#564293

ans : I have not installed Layouts plugin.
Okay my apologies. If you disable everything but Types and Views, is the conditional working as expected?

#564306

No, It is not working

#564312
usermeta.png

Types fields typically have the 'wpcf-' prefix in the database, as seen in the screenshot here. How was the _new_user custom field created, and how was data saved into this custom field?

#564542

I have added filter for custom field..it is being created when user register in to the site.

function user_register_add_meta($user_id) { 
	add_user_meta($user_id, '_new_user', '1');
    add_user_meta($user_id, 'is_password_changed', '0');
    add_user_meta($user_id, 'verification_code',random_password());
}
add_action('user_register', 'user_register_add_meta');
#564628
Screenshot_17.png

i have created new meta filed..and tried below code but not working

[wpv-conditional if="('[types usermeta='wpcf-is-password-changed'][/types]' eq 'no' )"]
How do you do [types usermeta="wpcf-is-password-changed"][/types] [/wpv-conditional]
#564810

Okay I see. Try this:
1. In Types > User Fields, make sure you have a custom field with slug "is-password-changed". If not, create one.
2. Modify your custom code to store information the Types User meta field. Add the wpcf- prefix to the field slug like this:

add_user_meta($user_id, 'wpcf-is-password-changed', 'no');

3. Test by creating a new User. You should see the is-password-changed field in the User's profile set to "no". If you do not see the field in the User's profile, we need to investigate why.
4. Test the value of the field with this shortcode:

Test is password changed: [types usermeta='is-password-changed' output='raw'][/types]

You should see "no" output on your site when logged in as the new user. Specifying output="raw" is important if you plan to use this value in a conditional, because otherwise additional formatting may be applied that will break your conditional logic.

Let me know how it goes.

#564974
step1.png
step2.png
step3.png
step4.2.png
step4.1.png

I have followed steps mentioned by you..I cant see value on my page.

Please check attached screenshot for all 4 steps.

Thanks

#565178

Okay and you're logged in as a User who has the ispassword-changed field set to 'no' when you test this, correct? The same code works for me on a local installation, so there must be something else going on. Is it possible to put up a test site somewhere so I can log in and take a look? If so, please send login credentials for a User who the value "no" set for the ispassword-changed field. Then let me know the steps to take so I can view the test message on the front-end of the site. Private reply fields are enabled here.

If that's not possible, I need to see more screenshots showing the rest of the View in your image of step 4.1

#565276

Okay I see the problem. You'll need to add the user_current attribute in the usermeta field shortcodes, both in the text output and in the conditional:

Test is password changed: [types usermeta="ispassword-changed" user_current="true"][/types]
[wpv-conditional if="('[types usermeta='ispassword-changed' user_current='true' output='raw'][/types]' eq 'no' )"]
How do you do [types usermeta="ispassword-changed" user_current='true' output='raw'][/types][/wpv-conditional]

I've made that change in the content template for you. Please check and let me know if the conditional is behaving as expected now.

#565742
Screenshot_14.png
Screenshot_13.png

I see the condition you put..but it is not working for me as expected..I would like to display popup window if value of "ispassword-changed" is "no"..I have logged in using user id 62..value for 'wpcf-ispassword-changed' in the database is "yes" so It should not display popup on dashboard..

Can I put wpv conditional is js editor?

Please check attached screenshot for the same.

Thanks

#565747

It is fixed

#565885
Screenshot_15.png
[types usermeta='nickname' user_current='true' output='raw'][/types]

Please check attached screenshot from the database.