WordPress Importer Plugin

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;
	} );
} );

Revision #4
Created 27 April 2023 06:53:12 by Sander
Updated 3 May 2023 09:41:10 by Sander