2

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? – Andy Macaulay-Brook Sep 23 '16 at 9:07
4

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

| improve this answer | |
  • 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. – Tiffany Israel Sep 1 '18 at 5:39
  • does this still work? – Latheesh V M Villa Nov 8 '18 at 18:32
  • @LatheeshVMVilla Yep! – Syed Fakhar Abbas Nov 8 '18 at 22:32
  • hi, please have a look at this question : wordpress.stackexchange.com/questions/318704/… – Latheesh V M Villa Nov 9 '18 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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