• Resolved mdv1988

    (@mdv1988)


    Dear reader im trying to get a custom hook to work with importing image to a gallery.

    the hook im using atm inside the function editor of the import is:

    <?php
    // ----------------------------
    // Gallery import
    // ----------------------------
    
    function gallery_id_url($post_id, $att_id, $filepath, $is_keep_existing_images = '')
    {
        $key = 'vehicle_image_gallery';  // Edit this: Set meta key for gallery array here
        $size = 'full';     // Edit this: Set WordPress image size for the URL here (e.g. "full" or "thumb")
    
        $gallery = get_post_meta($post_id, $key, TRUE);
        if (empty($gallery)) {
            $gallery = array();
        }
    
        if (!isset($gallery[$att_id])) {
            $src = wp_get_attachment_image_src($att_id, $size);
            $gallery[$att_id] = $src[0];
            update_post_meta($post_id, $key, $gallery);
        }
    }
    
    add_action('pmxi_gallery_image', 'gallery_id_url', 10, 4);
    ?>

    Screenshot of the import screen:
    https://ibb.co/ky7CcwT

    Copy paste of value:
    a:2:{s:3:”url”;s:78:”https://example.com/wp-content/uploads/2022/07/27395319-1.jpg&#8221;;s:2:”id”;s:4:”7469″;}

    i really hope you can help me out.
    Thanks in advance,

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

    (@wpallimport)

    Hi @mdv1988,

    In addition to removing the “vehicle_image_gallery” custom field from the Custom Fields section of the import template, you would need to adjust this part of the code:

    $gallery[$att_id] = $src[0];

    To save the data in the required format, which appears to be something like this:

    $gallery[] = array(
    			'url' => $src[0],
    			'id'  => $att_id
    		);

    That said, we aren’t able to help with custom code, so I’d suggest posting your question on to a Q&A site like StackOverflow if my example doesn’t work.

Viewing 1 replies (of 1 total)
  • The topic ‘Import to gallery’ is closed to new replies.