I want this custom field to use the excerpt if it is left blank. However, it appears as though the excerpt is getting saved after this function runs (it's always 1 'publish' click behind).
Any idea how to run this function after the excerpt is saved? Or is it running at the correct time and I'm just doing something wrong?
function save_seo_meta($post_id) {
$seo_desc = (isset($_POST['seo-desc']) && $_POST['seo-desc']) ? $_POST['seo-desc'] : get_the_excerpt();
update_post_meta($post_id, '_seo-desc', $seo_desc);
}
add_action('save_post', 'save_seo_meta');
Simple solution: just use the post data