Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by Yaron 4 years, 10 months ago.

Assisted by: Bigul.

Author Posts
July 29, 2020 at 12:33 pm #6700119

Yaron

I'm import data from a 3rd party system using API.
for each item i import, i create new post in the main Hebrew language and populate it with ACF data. i have also the data in English ready in vars in my script, but i don't know how to create also the English version of the same post.

I'm using a custom post "movies".

here is the part that i check if the post exists
$moviePost = get_page_by_title( $postTitle, OBJECT, 'movies' );
if ( $moviePost == null ) {
$post_id = wp_insert_post( $post );
} else {
// don't create new post
$post_id = $moviePost->ID;
}

and here the part where i update the post data:
update_post_meta( $post_id, '_visibility', 'visible' );
update_post_meta( $post_id, 'lang', $langHeb );
update_post_meta( $post_id, 'category', $category );
update_post_meta( $post_id, 'year', $year );
update_post_meta( $post_id, 'country', $countryHeb );
update_post_meta( $post_id, 'duration', $duration );
update_post_meta( $post_id, 'program', $programHeb );
wp_set_post_terms( $post_id, $tag, 'competition', true);

What is the link to your site?
this is a sample link to an Hebrew film page:
hidden link

July 29, 2020 at 7:11 pm #6702877

Bigul
WPML Supporter since 01/2013

Languages: English (English )

Timezone: Europe/Vienna (GMT+02:00)

Hello,

Welcome to the WPML support forum. I will do my best to help you to resolve the issue.

We have an API called wpml_set_element_language_details to update the language details of a Post or Taxonomy term. Please check the following URL for more details.

https://wpml.org/wpml-hook/wpml_set_element_language_details/

I can see some custom solutions from our clients on the following ticket. It may be helpful for you. But please note, we haven't tested it yet because of the customized requirements.

https://wpml.org/forums/topic/programmatically-create-post-in-different-languages/

--
Thanks!

Bigul