• Resolved logicred

    (@logicred)


    I have written an XML addon which takes a single image from my feed using your documentation example and it works great!:

    $my_addon->add_field( ‘property_featured_img’, ‘Property Featured Image’, ‘image’ );

    I can extract the attachment_id for my plugin perfectly using this:

    $attachment_id = $data[‘property_featured_img’][‘attachment_id’];

    I would now like to import multiple images, but am not clear how to extract the attachment_id number from each one using the example you give below.

    $my_addon->import_images( ‘property_images’, ‘Property Images’ );

    Ideally, I would like an array of attachment_id values of the images.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @logicred

    The “property_images” function in your example will receive three parameters: $post_id, $attachment_id, $filepath. Here’s an example of how you could add an array of the attachment IDs inside the “_my_custom_images” custom field:

    $my_addon->import_images( 'property_images', 'Property Images' );
    
    function property_images( $post_id, $attachment_id, $filepath ) {
        global $my_addon;
        $key = '_my_custom_images';
        $current_images = get_post_meta( $post_id, $key, true );
        if ( ! empty( $current_images ) ) {
            $current_images = maybe_unserialize( $current_images );
        } else {
            $current_images = array();
        }
    
        if ( ! in_array( $attachment_id, $current_images ) ) {
            $current_images[] = $attachment_id;
            update_post_meta( $post_id, $key, $current_images );
        }
    }

    See also: https://github.com/soflyy/wp-all-import-action-reference/blob/master/all-import/pmxi_gallery_image.php.

    Thread Starter logicred

    (@logicred)

    Perfect, thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom addon – multiple image import’ is closed to new replies.