Skip to content

Instantly share code, notes, and snippets.

@andrii-kvlnko
Created November 24, 2020 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrii-kvlnko/b6d20a2ae822d5d501fc81a6ac041330 to your computer and use it in GitHub Desktop.
Save andrii-kvlnko/b6d20a2ae822d5d501fc81a6ac041330 to your computer and use it in GitHub Desktop.
Set Post attachement from one lang to another
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