I am inserting posts into a database using wp_insert_post function once the post is inserted using below line of PHP

$postId = wp_insert_post($array)

I can insert values in my advanced custom fields using add_post_meta function but I didn't find anything to insert the SEO title or the meta description specifically in the Yoast SEO plugin.

Can anyone help me with this?

  • 1
    Yoast support ought to be able to tell you the names of the custom fields used. Have you tried their website? Commented Sep 23, 2016 at 9:07

1 Answer 1


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!


  • 1
    This was super helpful, thank you! I used it in a loop to populate the info pragmatically to give me a head start on imported woocommerce products. The problem I'm running into was that I was going to use the yoast color system to see which products needed extra SEO attention but when the values are written this way it doesn't calculate the SEO scores and just give gray circles instead. I have to open a product, then update it to see the score. Not even bulk updating on the backend or looping through products and saving them through a function works. Commented Sep 1, 2018 at 5:39
  • does this still work?
    – user145078
    Commented Nov 8, 2018 at 18:32
  • @LatheeshVMVilla Yep! Commented Nov 8, 2018 at 22:32
  • hi, please have a look at this question : wordpress.stackexchange.com/questions/318704/…
    – user145078
    Commented Nov 9, 2018 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.