Skip Navigation

[Resolved] how set the conditional logic with user custom field

This support ticket is created 5 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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

Last updated by Minesh 5 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#1171224

I am trying to: So, I'm trying to display the user image from custom field when an image is uploaded, if there are no image uploaded to display a specific image.
The user image custom field is generated by Unlimited Membership Pro, but it is managed by Toolset.
I'm trying to do that using this code

[wpv-conditional if="( '[types usermeta='ihc_avatar' title='%%TITLE%%' alt='%%ALT%%' size='full' user_is_author='true'][/types]' eq '[wpv-post-author format='profile_picture' profile-picture-shape='custom']' )"][types usermeta='ihc_avatar' title='%%TITLE%%' alt='%%ALT%%' align='center' size='custom' width='350' height='350' proportional='false' resize='crop' user_is_author='true'][/types][/wpv-conditional]
[wpv-conditional if="( '[types usermeta='ihc_avatar' title='%%TITLE%%' alt='%%ALT%%' size='full' user_is_author='true'][/types]' eq '[wpv-post-author format='profile_picture' profile-picture-shape='custom']' )" evaluate="false"]<img src="<em><u>hidden link</u></em>" width="350" height="350" align="middle">[/wpv-conditional]

Link to a page where the issue can be seen: hidden link and hidden link

I expected to see: So, if the image is uploaded I expected to display that image, if it is not uploaded to display the specific image.

Instead, I got: when the image is uploaded the uploaded image is not dosplayed, when the image is not uploaded I display the specific image correctly.

#1171233

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I would like to know here are you checking the current logged in user image?

Additionally, how you wrote the conditional shortcode does not look the correct way. I need to check how the field "ihc_avatar" value stored in the database.

*** 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

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

#1171246

Minesh
Supporter

Languages: English (English )

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

So, the site is a membership site, and in the Profile CPT every user can create only one profile page. And than, if it is possible, I think that a fastest solution is to sync the Profile CPT featured image with the user image and vice versa on upload. And, insted to use the user image custom field to display the user image in Profile CPT post, use the featured image that permit me to have more settings to display the image.
=> OK - so basically you want to copy the featured image of Profile CPT to the field ihc_avatar?

Additionally, I would like to again clarity your requirement here that if ihc_avatar has image - display that image otherwise you want to display the user profile image - correct?

#1171287

If it is possible I think that the fastest way is to copy the featured image of Profile CPT to the field ihc_avatar that it is a user custom field, and in the Profile CPT post I will display the featured image as user profile image becuse with sync now are indentical, and with the featured image I can set automatically that if the featured image has image the display the feature image, otherwise display a standard avatar that I uploaded before.

I need to do this, because I'm working to create a messaging system that it use the User image and if the User image is different from the Profile CPT post featured image, is too difficult for the users to know from which person who had a profile page comes the messages.

#1171340

Minesh
Supporter

Languages: English (English )

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

Ok - I've added a new code snippet under Toolset => Settings => Custom Code => Copy featured Image
=> hidden link

function func_copy_featured_image_to_user_field( $post_id, $post ){
    if ( 'profilo' == $post->post_type ) {
      
      $author_user_id = $_POST['post_author'];
   //   $thubnail_id = $_POST['_thumbnail_id'];
      $featured_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
      
        update_user_meta($author_user_id, 'ihc_avatar ', $featured_url);
    }
      
   
}
add_action( 'save_post', 'func_copy_featured_image_to_user_field', 30, 2 );

When you will submit the post - it will automatically copy the featured image of Profile CPT to user custom field ihc_avatar. Could you please confirm.

#1171348

Hi Minesh, yes, it work very fine!
Now, I'm trying to set the conditional logic to display e general image when there is not a featured image selected.

#1171698

H Minesh,
something was wrong, I don't know whats append. Now all the custom layout style that I have built with Divi desappear. All css customizations and also the divi style are not visible. I see the page structure but not css.
Why?
What should I do to solve the issue?

#1171700

What I'm doing before the issue was to regenate the thumbnail with the WP Media Folder plugin integrated function.

#1171712

I have found the nature of issue. It was some conflict with the Wp Smush Pro CDN service....

#1172210

Minesh
Supporter

Languages: English (English )

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

I'm glad that you able to found the conflicting plugin that was causing the issue.

Well - as your original issue is resolved, I spit the ticket to display the here with your new question:
=> https://toolset.com/forums/topic/split-how-set-the-conditional-logic-with-user-custom-field-how-to-conditionally-show-featured-image/

Please feel free to resolve this ticket.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.