Inserting Post Using wp_insert_post. How to Fill Yoast Plugin SEO Fields
-
07-01-2021 - |
Domanda
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?
Soluzione
You can use the update_post_meta function to insert the Yoast Plugin data. Yoast uses 3 post meta keys for each post:
- _yoast_wpseo_title ( use for SEO title )
- _yoast_wpseo_focuskw (For meta keywords )
- _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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange