• Resolved davidjoker

    (@davidjoker)


    Hello,
    I am trying to update all the wordpress post title and its content for different languages.
    I tried to track the field value of the title but all the title field have the same id=”title” which mean if I use the following wp_update_post function, it will have only one same title.

    // Update post 37
    $my_post = array(
    ‘ID’ => 37,
    ‘post_title’ => ‘This is the post title.’,
    ‘post_content’ => ‘This is the updated content.’,
    );

    // Update the post into the database
    wp_update_post( $my_post );

    I tried to track the content field like this:

    View post on imgur.com

    and all of the post title have the same ID:

    View post on imgur.com

    kindly help me how to update the post content and title for different language without manually thing.

    • This topic was modified 5 years, 11 months ago by davidjoker.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Alex Gor

    (@alexgff)

    Try use language marks

    
    $my_post = array(
    ‘ID’ => 37,
    ‘post_title’ => ‘{:en}This is the post title.{:}{:de}Title for German{:}’,
    ‘post_content’ => ‘{:en}This is the updated content.{:}{:de}Content for German{:}’,
    );
    
    Thread Starter davidjoker

    (@davidjoker)

    Thank you. It work, but it deleted the default post title and content (in english). Is there any way to add translations but not delete the original post title and content?

    • This reply was modified 5 years, 11 months ago by davidjoker.
    • This reply was modified 5 years, 11 months ago by davidjoker.
    Plugin Contributor Alex Gor

    (@alexgff)

    For example

    
    $post = get_post(37);
    $post_title_en = WPGlobus_Core::text_filter($post->post_title, 'en', WPGlobus::RETURN_EMPTY);
    $post_content_en = WPGlobus_Core::text_filter($post->post_content, 'en', WPGlobus::RETURN_EMPTY);
    
    $post_title = array(
    	'en'=>$post_title_en,
    	'de'=>'Title for German'
    );
    
    $post_content = array(
    	'en'=>$post_content_en,
    	'de'=>'Content for German'
    );
    
    $my_post = array(
    	'ID' => 37,
    	'post_title' => WPGlobus_Utils::build_multilingual_string($post_title),
    	'post_content' => WPGlobus_Utils::build_multilingual_string($post_content),
    );
    
    Thread Starter davidjoker

    (@davidjoker)

    thanks. it works.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘unable to update all the post’s contents/titles in WPGLOBUS fields’ is closed to new replies.