What is the best way to update meta data automatically?
Hi There,
Can you please tell me the easiest way to update yoast meta data automatically,
I've been trying this for hours without success, I think its because of the priority and how the yoast meta fields are created.
adding this directly on functions.php would work
update_post_meta('80', '_yoast_wpseo_title', 'Test Title' );
But something like this doesn't work
function save_metadata($post_id) {
$data = new PropertyData;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return $post_id;
if ('property-listing' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id))
return $post_id;
} elseif (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
update_post_meta($post_id, '_yoast_wpseo_title', $data->title );
update_post_meta($post_id, '_yoast_wpseo_metadesc', $data->desc );
update_post_meta($post_id, '_yoast_wpseo_metakeywords', $data->keyw );
}
add_action( 'save_post', 'save_metadata',99);
My code above works with genesis seo fields, custom field, and custom metaboxes fields, but its not working on Yoast SEO fields
Any help would be appreciated,
Thank you
Unfortunately, this is not a bug, but a support request. We use GitHub exclusively for (well-documented) bug reports, so we cannot help you here.
To receive free support for WordPress SEO we have the following channels:
- Yoast Knowledge base
- Support forums on WordPress.org
Or if you want personal support via email, you can purchase WordPress SEO Premium.
Thanks for your understanding.