Image advanced update via rest api

Support General Image advanced update via rest api

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #35850
    DragosDragos
    Participant

    Hi. 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.

    #35851
    DragosDragos
    Participant

    can you give me some code snippet or a function that will append multiple image id on the image advanced field

    #35870
    DragosDragos
    Participant

    Hi Long. Need help for this.

    #35878
    Long NguyenLong Nguyen
    Moderator

    Hi 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/#data

    #35887
    DragosDragos
    Participant

    Hi 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.

    #35897
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The function add_post_meta() works as well on my local site, please check this screen record https://monosnap.com/file/XPzx3xXkAdjR6wQU9otZGdqI0g7bbu

    Code:

    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 );
    #35898
    DragosDragos
    Participant

    Hi,

    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?

    #35900
    DragosDragos
    Participant

    i 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.

    #35904
    Long NguyenLong Nguyen
    Moderator

    Hi,

    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.

    #35909
    DragosDragos
    Participant

    hi. 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);
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.