0

function sync_meta_fields_with_seo_meta_fields($post_id) {
 if (get_post_type($post_id) !== 'post') {
        return;
    }
    $meta_fields = [
        'SeoDescription' => 'meta_description',
        'SeoTitle' => 'meta_title',
    ];
    foreach ($meta_fields as $seo_key => $meta_key) {
        $seo_value = get_post_meta($post_id, $seo_key, true);
        if (!empty($seo_value)) {
   if (metadata_exists('post', $post_id, $meta_key)) {
             $meta_value = get_post_meta($post_id, $meta_key, true);
             if ($meta_value !== $seo_value) {
                 update_post_meta($post_id, $meta_key, $seo_value);
             }
            }
        }
    }
}
add_action('save_post', 'sync_meta_fields_with_seo_meta_fields', 20);

Jagdish Sarma Asked question 3 days ago
Add a Comment