Skip Navigation

[Gelöst] cred_save_data and image url

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem: I'm trying to copy a custom field from a post into a user field. The field is an image field. When I check the copied value with update_user_meta, the value is serialized in the database. How should I copy the field value correctly without serialization?

In the user meta field:

a:1:{i:0;s:86:"https://my-site.com/wp-content/uploads/2019/10/my-photo.jpg";}

Solution: When using get_post_meta, the third parameter will influence the returned data type. Use true in the third parameter to return only the first value, and prevent this serialization.

$photo_membre = get_post_meta ($post_id, 'wpcf-photo-identite-membre', true);
update_user_meta ($user_id, 'wpcf-photo', $photo_membre);

Relevant Documentation:
https://developer.wordpress.org/reference/functions/get_post_meta/

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

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Dieses Thema enthält 4 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Pat vor 5 Jahren.

Assistiert von: Christian Cox.

Author
Artikel
#1371423

Pat

Hello,

I'm using a Cred form for a specific postype and have defined an image custom field to upload a photo (photo-identite-membre).
I have also a cred_save_data in order to copy the url of the image inside a usermeta (photo).

So, in my cred_save_data, I'm using this :
$photo_membre = get_post_meta ($post_id, 'wpcf-photo-identite-membre');
update_user_meta ($user_id, 'wpcf-photo', $photo_membre);

In my postmeta, I' m getting the right info (versteckter Link
but in my usermeta, here is what I'm getting : a:1:{i:0;s:86:"versteckter Link";}

Any idea why the url is in serialized format and how to get it in the standard way?

Regards
Pat

#1371479

Hi, is it possible the photo custom field allows multiple values in either wpcf-photo or in wpcf-photo-identite-membre? Are either of these set to allow multiple values?

#1371487

Pat

Hi Christian,

No, only one item for these fields.
Regards
Pat

#1371543

What if you add the third parameter 'true' to get_post_meta:

$photo_membre = get_post_meta ($post_id, 'wpcf-photo-identite-membre', true);
#1374459

Pat

Hi Christian,

You're right. I should have thought about it before !!!
Regards
Pat