Inserting Post Using wp_insert_post. How to Fill Yoast Plugin SEO Fields

You can use the update_post_meta function to insert the Yoast Plugin data. Yoast uses 3 post meta keys for each post:

  1. _yoast_wpseo_title ( use for SEO title )
  2. _yoast_wpseo_focuskw (For meta keywords )
  3. _yoast_wpseo_metadesc (For meta descriptio )

You can find all these meta key under postmeta table


    $new_id = wp_update_post($array);

    update_post_meta( $new_id, '_yoast_wpseo_title', 'SEO Title' );

    update_post_meta( $new_id, '_yoast_wpseo_focuskw', 'keyword1 keyword2' );

    update_post_meta( $new_id, '_yoast_wpseo_metadesc', 'SEO Meta Descr' );

Hopefully, It will work for you!

Thanks