Image advanced update via rest api
- This topic has 9 replies, 2 voices, and was last updated 2 years, 11 months ago by
Dragos.
-
AuthorPosts
-
May 3, 2022 at 7:57 AM #35850
Dragos
ParticipantHi. I have this function below.
function add_images($id, $title, $img){
update_post_meta( $id, 'property_images', 4311);
}the property_images is the id of image advance field. the 4311 is the id of the media. how can i add multiple images on update_post_meta function ? for example i have multiple ids. how to add that and have a multiple image. whenever i make it as an array, it doesnt work.
May 3, 2022 at 7:58 AM #35851Dragos
Participantcan you give me some code snippet or a function that will append multiple image id on the image advanced field
May 4, 2022 at 3:46 PM #35870Dragos
ParticipantHi Long. Need help for this.
May 4, 2022 at 9:27 PM #35878Long Nguyen
ModeratorHi Dragos,
You can use the function
add_post_meta()
to add more value to a post with the same meta key (field ID). Read more on the documentation https://developer.wordpress.org/reference/functions/add_post_meta/
https://docs.metabox.io/fields/image-advanced/#dataMay 5, 2022 at 8:05 AM #35887Dragos
ParticipantHi long,
Thank you for the reply. I already tried the add_post_meta, It did work on image gallery, can add multiple values, but theres one issue, if i go to the backend and try to edit it, the property images are not showing, even though theere are pictures on the frontend.
check this image: https://snipboard.io/JynRTp.jpg
image above is dine with add_post_meta
however this one is by manual adding on backend. https://snipboard.io/bZXMe1.jpg
you can see that there are images showing on the field and add media.
so problem is when I want to update the images, I cannot do it on the first one because theres no media showing and cannot add also.
May 5, 2022 at 12:37 PM #35897Long Nguyen
ModeratorHi,
The function
add_post_meta()
works as well on my local site, please check this screen record https://monosnap.com/file/XPzx3xXkAdjR6wQU9otZGdqI0g7bbuCode:
add_action( 'init', function() { add_post_meta( 2192, 'image_advanced_v4mq8tny1nh', 2484, false ); add_post_meta( 2192, 'image_advanced_v4mq8tny1nh', 2483, false ); add_post_meta( 2192, 'image_advanced_v4mq8tny1nh', 2481, false ); }, 99 );
May 5, 2022 at 2:06 PM #35898Dragos
ParticipantHi,
Thank you. it is actually working. i just need to resave the post manually. can I run an action to save it again inside a function call?
May 5, 2022 at 3:23 PM #35900Dragos
Participanti also have one issue. i follow this tutorial https://metabox.io/display-uploaded-images-as-wordpress-image-gallery/ for converting the iamge advanced to wordpress gallery. the problem is in order for the gallery to show i need to attach each images to specific post. it is not automatically attaching to the post on which it was uploaded.
check this image: https://snipboard.io/nYQWeq.jpg
the first one i manually attached to the post, the others shows it is not attached although it was already uploaded to the post.
May 5, 2022 at 9:08 PM #35904Long Nguyen
ModeratorHi,
If you use the helper function to get images from the custom field, no need to attach the image to a post because this option works like a custom field with the meta key
_wp_attached_file
.May 6, 2022 at 8:04 AM #35909Dragos
Participanthi. the uploading comes from the flowmattic plugin which is not directly attached to the post. the upload comes first then after that it will just create a new post and set the correct images via flowmattic again.
what i did is to add some function that will attach the media to the post.
$attach = array( 'ID' => $img, 'post_parent' => $id ); wp_update_post( $attach ); clean_attachment_cache($img);
-
AuthorPosts
- You must be logged in to reply to this topic.