Created
July 1, 2022 02:43
-
-
Save ValeriiVasyliev/31388815499a5e71bb58059fd58d9636 to your computer and use it in GitHub Desktop.
Extend the export of WordPress for media
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define( 'DOING_AJAX', true ); | |
define( 'WP_ADMIN', true ); | |
define( 'WP_IMPORTING', true ); | |
$err = array(); | |
/** Load WordPress Bootstrap */ | |
require_once 'wp-load.php'; | |
require_once 'wp-admin/includes/image.php'; | |
$args = array( | |
'post_type' => get_post_types(), | |
'posts_per_page' => -1, | |
'post_status' => 'any', | |
'meta_query' => array( | |
'relation' => 'AND', | |
array( | |
'key' => '_thumbnail_id', | |
'compare' => 'EXISTS', | |
), | |
), | |
); | |
$query = new \WP_Query( $args ); | |
if($query ->have_posts()) : | |
while($query->have_posts()) : $query->the_post(); | |
set_time_limit( 120 ); | |
$post_id = get_the_ID(); | |
$thumbnailId = get_post_meta( $post_id, '_thumbnail_id', true ); | |
$wpAttachedFile = get_post_meta($thumbnailId, '_wp_attached_file', 1 ); | |
if (!empty($wpAttachedFile)) { | |
update_post_meta($post_id , '_thumbnail_file', $wpAttachedFile ); | |
} | |
printf( | |
__( 'Importing %s ... %s' ) . PHP_EOL, | |
get_the_title(), | |
$wpAttachedFile | |
); | |
endwhile; | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment