Migrate custom post types automatically (WPML compatible)
(WPMS v.3.5.1 + WPML, Attachments v.3.3.2)
I just want to post some ideas here related to the migration of attachments attached to custom post type posts.
Problem was, that I hit the migration button before overriding the default attachment instance in functions.php. Doing so, only attachment from type ‘page’ and ‘post’ become migrated, and then there is the migration option missing in the admin view! I guess, that there some people out there making the same fault.
First, I reseted the option for migration this way:
get the migraton button back
Then I edited the following lines (all changes related to class.attachments.migrate.php):
foreach( $legacy_attachments_settings['post_types'] as $post_type => $value ) if( $value ) $post_types = $post_type;
because due to migration process, it is not necessary to scan for registered posttypes. In every case the old data will become obsolete, so everything has to be converted on every migration process. So, just modify the query below to post_type=>’any’:
$args = array( 'post_type' => 'any', // get all posts of every type or custom type 'post_status' => 'any', 'posts_per_page' => -1, 'meta_key' => '_attachments', 'suppress_filters' => true // suppress filters, so that wpml does not hook in and wp returns every language );
Also in this place, add ‘suppress_filters’, so that WPML plugin will not be able to filter to records from the blogs current admin language only, but return really all languages.
Clear obsolete meta-data from database – added this after line 149:
// clean up database delete_post_meta( $query->post->ID, '_attachments' );
As an alternate you can manually run a sql query and remove all records with ‘_attachments’ as meta_key in table ‘postmeta’, so you have the possibility to verify successful migration first.
By the way: To my opinion it is not quite optimal, that there is a default instance of attachments without registering that. It is difficult, to remove that instance, override it is simpler.
define( 'ATTACHMENTS_DEFAULT_INSTANCE', false );
only works in wp-config.php for me, I guess in functions.php it is too late. Defining plugin specific configuraton in the wp-config is probably not best practice.
- The topic ‘Migrate custom post types automatically (WPML compatible)’ is closed to new replies.