wordpress-seo icon indicating copy to clipboard operation
wordpress-seo copied to clipboard

What is the best way to update meta data automatically?

Open SilverKenn opened this issue 12 years ago • 1 comments

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

SilverKenn avatar Oct 27 '14 16:10 SilverKenn

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:

Or if you want personal support via email, you can purchase WordPress SEO Premium.

Thanks for your understanding.

tacoverdo avatar Oct 31 '14 14:10 tacoverdo