• Resolved latheeshvmv

    (@latheeshvmv)


    I am trying to update the field when post status changes to published. it is getting the values properly but not updating ..when i check the what update field is returning -it shows some number …please help .. not sure whether i should use this along with transition_post_status

    Update – I have tried below hooks // the action is getting triggered but the fields are not updating

    1. publish //works but no update is happening

    2. save_post && save_post_l //works but no update is happening.

    add_action('transition_post_status', 'updated_to_publish', 10, 3);
    function updated_to_publish($new_status, $old_status, $post)
    {
    
        if (($new_status == 'publish') && ($post->post_type == 'l')) {
    
            $post_id = $post->ID;
    
            if (get_field('advanced_option_edit_seo', $post_id)) {
    
                if (defined('WPSEO_VERSION')) {
    
                    $metatitle = get_field('seo_title', $post_id);
                    $metadesc = get_field('seo_meta_description', $post_id);
                    $metakeywords = get_field('seo_keyword', $post_id);
    
                    update_post_meta($post_id, '_yoast_wpseo_title', $metatitle );
                    update_post_meta($post_id, '_yoast_wpseo_metadesc', $metadesc );
                    update_post_meta($post_id, '_yoast_wpseo_focuskw', $metakeywords);
    
                }
    
            }
    
        } else {
            return;
        }
    
    }
Viewing 1 replies (of 1 total)
  • Plugin Support devnihil

    (@devnihil)

    Unfortunately we can’t offer support on custom code. Since we don’t want to take the risk that we break your website by suggesting incorrect or incomplete code, we cannot advise you on how to make such changes. Maybe someone watching these forums can assist you further, but if your topic is inactive for 7 days, we’ll mark it as resolved to keep the overview.

    Thank you for your understanding.

Viewing 1 replies (of 1 total)
  • The topic ‘update_post_meta() not working when used with WordPress action’ is closed to new replies.