• Resolved jvan

    (@jvandelaar)


    I have a specific scenario where I’m importing information and images to a custom post type.

    The custom post type has a custom field called “images” that uses image IDs attached to the custom post separated by commas.

    The below script works great when the custom post is imported and created (for the first time):

    function gallery_ids_in_string($post_id, $att_id, $filepath)
    {
        $key = 'images'; // Edit this: Set meta key for gallery array here
        $separator = ",";
        $gallery = get_post_meta($post_id, $key, true);
        if (is_string($gallery) || is_empty($gallery) || ($gallery == false)) {
            $gallery = explode($separator, $gallery);
            if (!in_array($att_id, $gallery)) {
                if ($gallery[0] == '') unset($gallery[0]);
                $gallery[] = $att_id;
                update_post_meta($post_id, $key, implode($separator, $gallery));
            }
        }
    }
    add_action('pmxi_gallery_image', 'gallery_ids_in_string', 10, 4);

    The field updates as expected with the attachment ids separated by commas. The Problem is that the above script doesn’t update the custom field when the import only updates the post.

    I’ve tried using the hook pmxi_saved_post but no luck. Any ideas?

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

    (@wpallimport)

    Hi @jvandelaar

    The Problem is that the above script doesn’t update the custom field when the import only updates the post.

    It sounds like the images aren’t being updated when the post is updated. Please check the Import Settings and make sure images are set to be updated.

    Plugin Author WP All Import

    (@wpallimport)

    @jvandelaar

    I’m marking this as resolved since we haven’t heard back. Let me know if you’re still having this issue. Anyone else, please start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Update custom field after post created or updated’ is closed to new replies.