Support

Account

Home Forums Add-ons Gallery Field Load ACF Gallery from XMLRPC

Solving

Load ACF Gallery from XMLRPC

  • Hi,

    i need to load xml data into custom post, i’ve added some acf filed (number, text and gallery).
    For create a new post i’use wp_insert_post and with add_post_meta set the acf fields value (for text and number), how can i do for gallery fields?
    I can upload the images too and generate all image sizes but how can assign one or more image to my custom post?

    Thanks

    • Elliot

    • September 18, 2013 at 11:46 am

    Hi @mg_strategia

    Easy. All you need to do is swap the add_post_meta function for the ACF update_field function, you can read more about this function here:
    Please note that the parameters are different.

    To save a gallery field value, just save an array containing all the image ID’s
    To get the save function to work correctly, you will need to use the field_key instead of the field_name. This is explained on the doc page too.

    http://www.advancedcustomfields.com/resources/functions/update_field/

    Cheers
    E

  • Hi, i’ve use update_field function but the data are not saved correctly, i’ve load my image with wp.uploadFile RPC Query and get the ID METADATA by $response[‘id’] with wp_get_attachment_metadata function; now i’ve create the array containing id, title, caption, url, sizes and so on… after that i’ve this code:

    
    $value = get_field("field_5234c710a5b38", $post_id);
    $value[] = $arrayPhoto;
    update_field( "field_5234c710a5b38", $arrayPhoto, $post_id );
    

    After that the gallery are empty, into db i see the field into wp_postmeta are different as a manual load, i’ve a metakey gallery (field_5234c710a5b38) with the serialized arrayPhoto (a:13:{i:0;a:9:{s:2:”id”;i:2272;s:3:”alt”;s:0:””;s:5:”title”;s:20:”import_1513072……), into other field generated by wordpress there are a serialized object with the ID of two metakey (_wp_attached_file and _wp_attachment_metadata) with the array of data (a:1:{i:0;s:4:”2182″;}).

    How can i fix it?

    Thanks

    • Elliot

    • September 19, 2013 at 2:02 pm

    Hi @mg_strategia

    As previously mentioned, you only need to save the image ID’s, not any other data

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.