Quantcast
Channel: polylang – WordPress.org Forums
Viewing all articles
Browse latest Browse all 11471

hugolaporte on "[Plugin: Polylang] Create posts translations on existing site with large number of records (700)"

$
0
0

Thanks Chouby! Exactly what I was looking for. I've done it like this so far. Just wondering how to retrieve the synchronized categories and synchronized post fields:

$args = array(
  'post_type' => 'post',
  'orderby' => 'ID',
  'order' => 'asc',
  'post_status' => 'publish',
  'posts_per_page' => -1,
);

query_posts($args);

while ( have_posts() ) : the_post();

	$fr_post_id = get_the_ID();

	$post_categories = wp_get_post_categories( $fr_post_id );

	$post = array(
		'post_title' 	=> get_the_title(),
		'post_content' 	=> get_the_content(),
		'post_status'  	=> 'publish',
		'post_author'   => get_the_author(),
		'post_category'  => $post_categories  // HOW TO GET THE SYNCHRONIZED CATEGORIES ?
	);

	global $polylang;
	$post_id = wp_insert_post($post);
	$post_en = $polylang->model->set_post_language($post_id, 'en');
	$polylang->model->save_translations('post', $post_id, array('fr' => $fr_post_id));

endwhile;
wp_reset_query();

Viewing all articles
Browse latest Browse all 11471


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>