Skip to main content

WordPress Importer Plugin

  • It has support for: deduplication (see below), mapping image urls
  • All imported posts haven import_id meta which is the ID they had in the import WXR.

Post processing:

Example

/**
 * Usage: IMPORT_POST_TYPES=blogpost,attachment wp import ...
 */
WP_CLI::add_hook( 'before_invoke:import', function () {
	add_filter( 'wp_import_posts', function ( $posts ) {
		if ( getenv( 'IMPORT_POST_TYPES' ) ) {
			$post_types = explode( ',', getenv( 'IMPORT_POST_TYPES' ) );
			$post_types = array_map( 'trim', $post_types );
			$posts = array_filter( $posts, function ( $post ) use ( $post_types ) {
				return in_array( $post['post_type'], $post_types, true );
			} );

			return $posts;
		}

		return $posts;
	} );
} );