Created
November 24, 2020 19:23
-
-
Save andrii-kvlnko/b6d20a2ae822d5d501fc81a6ac041330 to your computer and use it in GitHub Desktop.
Set Post attachement from one lang to another
This file contains 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
add_action( 'wp', function () { | |
return; | |
if ( $_COOKIE['PHPSESSID'] !== 'xxxx' ) { | |
return; | |
} | |
global $sitepress; | |
foreach ( range( 1, 100 ) as $iteration ) { | |
dump( $iteration ); | |
$sitepress->switch_lang( 'ru' ); | |
$products = get_posts( | |
[ | |
'post_type' => 'product', | |
'post_status' => 'publish', | |
'posts_per_page' => 100, | |
'paged' => $iteration, | |
] | |
); | |
foreach ( $products as $product ) { | |
$thumbnail_ru = get_post_thumbnail_id( $product ); | |
$sitepress->switch_lang( 'uk' ); | |
$product_id_uk = $sitepress->get_object_id( $product->ID, 'page' ); | |
$result = set_post_thumbnail( $product_id_uk, $thumbnail_ru ); | |
dump( $result ); | |
} | |
} | |
dump( 'complete' ); | |
exit; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment