Skip Navigation

[Resolved] User custom field slug

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

Problem:
User custom field slug - set default value and use with conditional statement

Solution:

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/user-custom-field-slug/#post-1352381

Relevant Documentation:

This support ticket is created 5 years, 1 month 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by FelipeP5703 5 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1349639

Tell us what you are trying to do?

I had a post custom field radio for allowing the user to change their images in their custom post, but I decided to change from a custom post field to a custom user field, that way I can select the user and all his or her posts would allow or not to change their images.

So this user custom field slug is "mudar-fotos" and I added to the code below in Views:

<wpv-loop>
		[wpv-conditional if="( $(wpcf-mudar-fotos) eq '1' )"]
			[cred_form form='formulario-para-editar-anuncio-pode' post='[wpv-search-term param="f_editar"]']
		[/wpv-conditional]
		[wpv-conditional if="( $(wpcf-mudar-fotos) eq '2' )"]
			[cred_form form='formulario-para-editar-anuncio' post='[wpv-search-term param="f_editar"]']
		[/wpv-conditional]		
	</wpv-loop>

So I believe the problem might lie on wpcf-slug... I know this slug is used on custom post fields, but is it used for user custom fields?

I looked on the documentation and even searched for user custom field slug but couldn't find anything.

I already deleted the post custom field and wanted to use the User custom field instead. How do I do it?

#1349795

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

What if you try to use the following code:

[wpv-conditional if="( '[types usermeta='mudar-fotos' user_current='true' output='raw'][/types]' eq '1' )"]
 [cred_form form='formulario-para-editar-anuncio-pode' post='[wpv-search-term param="f_editar"]']
[/wpv-conditional]

[wpv-conditional if="( '[types usermeta='mudar-fotos' user_current='true' output='raw'][/types]' eq '2' )"]
            [cred_form form='formulario-para-editar-anuncio' post='[wpv-search-term param="f_editar"]']
[/wpv-conditional]      

Please check following doc for more info:
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/
[ Section: "Checking Types plugin shortcodes"]
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-types-fields-and-custom-fields/
=> https://toolset.com/documentation/customizing-sites-using-php/functions/#radio

#1350211
Mudar_fotos3.jpg
Mudar_fotos2.jpg
Mudar_fotos.jpg

Minesh,

Unfortunately it did not work. I thought all custom fields (posts and users custom fields) used the prefix "wpcf-"

I tried adding your code but also, it's not showing anything. Do I have to add "[types usermeta='mudar-fotos' user_current='true' output='raw'][/types]" to the front-end content tab in settings? I mean, I don't think it's a custom code, right?

#1351411

Minesh
Supporter

Languages: English (English )

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

I need to check on your install whats going wrong there. Can you please share problem URL where you added the conditional statement as well as wp-admin access details.

Please share access details of specific user if needed if I need to loggedin as different user than admin.

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

#1351907

Minesh,

For some reason the conditional display is working only after I change the User settings and the default settings are not taking precedence. Here is a video explaining - hidden link

#1352381

Minesh
Supporter

Languages: English (English )

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

Yes - exactly.

If the form you are using is the same before using which you are creating the user - for all custom fields for which you want to add a default value you need to add it as before:

For example:


add_action('cred_save_data','func_set_default_value_forusers',10,2);
function func_set_default_value_forusers($post_id,$form_data) {
 
    if ($form_data['id']==128) {
              $limit_user_posts = 2;
           update_user_meta($post_id, 'wpcf-numero-de-anuncios-pagos', $limit_user_posts);

           // setting default value for field mudar-fotos
           update_user_meta($post_id, 'wpcf-mudar-fotos', 1);

          // you can add same kind of code and replace the custom field name for other fields default values.
     }
}
#1353079

Minesh, you are the man! My issue is resolved now. Thank you!