Home › Forums › Add-ons › Gallery Field › update_post_meta() and gallery field
In my project I need to post images directly to db, without admin panel. For this purpose I’m uploading images with media_handle_sideload() and then update the post with update_post_meta().
To update gallery field I’m uploading images and then write its IDs to the string like that a:4:{i:0;s:4:”1174″;i:1;s:4:”1175″;i:2;s:4:”1176″;i:3;s:4:”1177″;}.
I understand that a:4 – means 4 images, i:0 – index (like in array), but can’t understand what is s:4 about. When I submit a post with GUI in admin panel it can be s:2 or s:3 or s:4. Please help me to figure it out, what is this value about?
The string you are referring to is a serialized array. You can first create an array of ID’s, and then save the array to the DB via the update_postmeta function will will serialize the array for you!
You can also make use of the handy update_field
function here:
http://www.advancedcustomfields.com/resources/functions/update_field/
Thanks
E
Actually, in the first message I wrote that I’m using serialized array a:4:{i:0;s:4:”1174″;i:1;s:4:”1175″;i:2;s:4:”1176″;i:3;s:4:”1177″;}
What I need is to understand what “s” parameter means! How can I determine its value?
If I add images to the gallery field via admin panel (not directly to db), this parameter equals to “2” or “3” or “4” but why precisely?
@semanalitics I believe the s:4 is the length of the string value.
For instance, in my database, I have this:
s:14:”Walk-in closet”
And
s:16:”Washer and dryer”
Note the values equal how many characters follows.
I found your thread trying to figure out how to update the values globally (to fix typos) without editing the values and resaving every page that used it. Figured I’d help you while continuing to look for my answer. 🙂
Cheers.
The topic ‘update_post_meta() and gallery field’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.