Parameter for wp_insert_post

Home Forums WordPress Plugins Language Switcher Parameter for wp_insert_post

Viewing 1 reply thread
  • Author
    Posts
    • #8588
      sweb1
      Participant

      I am using the standard method to insert a post on-the-fly:

      $post_data = array(
      'post_author' => $author_id,
      'post_category' => array($category_id),
      'tags_input' => $tags,
      'post_title' => $title,
      'post_content' => $content,
      'post_type' => 'post',
      'post_status' => 'publish'
      );
      $post_id = wp_insert_post($post_data);

      Can you tell me the parameter so that wordpress can set the language for language switcher for this post like
      ‘language_switcher’ => ‘FR’;

       

    • #8593
      Rafasashi
      Keymaster

      Sorry for the delay.

      First you need to build an array for the switcher:

      $switcher = array(
      	
      	'urls' => array(
      
      		'fr' => false,
      		'en' => 'https://',
      	),
      	'main' => 'fr',
      );

      Then update the 2 following post meta data:

      update_post_meta( $post_id, 'lsw_language_switcher', $switcher);
      
      update_post_meta( $post_id, 'lsw_main_language', $switcher['main']);

      If you are editing a post that already has settings don’t forget to merge the previous array with the new one:

      $switcher= get_post_meta( $post_id, 'lsw_language_switcher', true);
      
      // add/modify english url
      
      $switcher[urls]['en'] = 'https://';
      
      update_post_meta( $post_id, 'lsw_language_switcher', $switcher);
Viewing 1 reply thread
  • The topic ‘Parameter for wp_insert_post’ is closed to new replies.