• Hi Erolsk8,

    I’ve imported users and posts to a new site. The uploads folder was way to big to import/download/export, so I used rsync to copy it over.

    Of course, now I don’t have those in the WP media library, nor is the featured image for each post connected to the post.

    If I use Media Sync to add the uploads to the library, will that also resolve my issue of the featured images not working?

    I’ve got 10 years of uploads in there, any tips on doing this successfully? I say your notes on increasing execution time and loading inner directories, will start with those,

    thanks,

    Chris

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author erolsk8

    (@erolsk8)

    Hi @christopheran,

    I’m not sure, but it probably won’t do it automatically. But I think @simonkane did something similar, so maybe he could help. I created a hook function that happens right after wp_posts table is upaded and before wp_postmeta table is updated. So you can use it to customize what gets written to wp_postmeta. If I remember correctly, that’s where the connection about features post image should be.

    Here are some details about this custom hook:

    /**
     * Apply this filter to collect additional metadata and/or to run some additional actions,
     * e.g. to "auto-connect" items to pages, posts, and WooCommerce products.
     * Returning empty data will skip updating metadata (wp_update_attachment_metadata),
     * so this filter can also be used to totally overwrite updating attachment metadata.
     *
     * This filter can be used in a number of different ways:
     * 1.?to collect additional metadata,
     * 2. to run some additional custom actions
     *   (e.g. to "auto-connect" items to pages, posts, and WooCommerce products),
     * 3. to skip or completely overwrite updating the metadata (<code>wp_update_attachment_metadata</code> function),
     *   when this filter returns empty data (null).
     *
     * NOTE:
     * Things could break if the filter doesn't return proper attach data
     * and it hasn't created/updated the <code>wp_postmeta</code> table record (meta_key _wp_attachment_metadata).
     *
     * @since 1.2.5
     *
     * @param array $attach_data Data received from WP function: wp_generate_attachment_metadata
     * @param int $attach_id
     * @return array|null
     */
    function my_custom_media_sync_before_update_metadata($attach_data, $attach_id)
    {
      // Custom logic here
      return $attach_data;
    }
    add_filter('media_sync_filter_before_update_metadata', 'my_custom_media_sync_before_update_metadata', 10, 3);

    I hope this helps.

    Erol

    Plugin Contributor Simon Kane

    (@simonkane)

    @christopheran Was it you I just gave my filter snippet to over in the WooCommerce Slack?

    My snippet is very powerful for connecting Woo product images because it will match image names to products by SKU.

    For ordinary WP posts, my code can do that – but only under very limited cases — the image name has to have a way to be matched to the post name (slug I think is what I used).

    Beyond that, it would take digging into the OLD DB to find the attachment links, but then it’s still not easy to match up unless there’s a way to cross-reference (I’d have to dig into it for details).

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Will importing the library reconnect featured images?’ is closed to new replies.