vuongdinhngoc
5/3/2018 - 2:39 AM

Cross post from master to children

Cross post from master to children

<?php

require(dirname(__FILE__) . '/wp-blog-header.php');

$toBlogId = isset($_GET['to_blog_id']) && !empty($_GET['to_blog_id']) ? $_GET['to_blog_id'] : false;

$copyPost = CopyPost::GetInstance();

if ($toBlogId) {
	$args = array(
		'post_type' => 'post',
		'posts_per_page' => -1,
		//'post_status' => 'any',
		'meta_key' => META_KEY_IMPORTED,
		'meta_value' => 1,
		//'post__in' => [964170]
	);

	$query = new WP_Query($args);

	if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
		$pid = get_the_ID();
		$childPostID = $copyPost->CopyRootPostToBlog($pid, $toBlogId);

		if ($childPostID) {
			$children_meta = unserialize(get_post_meta($pid, '_HMMultipostMU_children', true));
			if (!empty($children_meta)) {
				$children_meta = [TO_BLOG_ID => $childPostID] + $children_meta;
			} else {
				$children_meta = [TO_BLOG_ID => $childPostID];
			}

			update_post_meta($pid, '_HMMultipostMU_children', serialize($children_meta));
		}

		//$_thumbnail_id = get_post_meta($pid, '_thumbnail_id', true);
		//update_post_meta($pid, '_post_thumbnail_id', $_thumbnail_id);
		print '<pre>';print_r('Done ' . $pid);print '</pre><hr>';
	endwhile; endif;
	wp_reset_query();
} else {
	echo 'blog_id is empty';
}