Support

Account

Forum Replies Created

  • Hi John,
    i read about WP core and i found the way to help me do it.
    Thank you for help!

  • Hello John,
    I access to the dababase and find in column meta_value, i seem something like field_585d2d2af8d69. Are they field key?

    Then i try edit your code and run test:

    add_action('acf/save_post', 'my_acf_save_post', 1);
    function my_acf_save_post() 
    {
        // you need the field key of the field you want to check
        $field_to_check_key = 'field_585d2d2af8d69';
        var_dump($field_to_check_key);
    
        $old_value = get_field('luc_nham_0_can', 339, false);  // 339 is curent post ID
        var_dump($old_value);
        // see if it is different than new value
        // also make sure the field key is set
        if (isset($_POST['acf'][$field_to_check_key]) &&
            $old_value != $_POST['acf'][$field_to_check_key]) 
        { 
            echo 'Hello the Wolrd';      // Test if the field has changed.
        }
      
      // Test current fields
      $curent_field = get_field('luc_nham_0_can');
      var_dump($curent_field);
    }
    
    // Shortcode to test
    add_shortcode('tess', 'my_acf_save_post');
    

    I try to change the testing field many time, but $old_value has updated same $curent_field, it not keep old value.

    You can see some images in this comment.
    This is the testing field in database
    This is the post to test

  • Hello John,
    I read the link but i do not really understand. My English is not good and i work with WP Just recently.
    I try some like this:

    function my_acf_save_post( $post_id ) {
        
        
        // array of field values
        $fields = $_POST['acf'];
    
        // specific field value
        $field = $_POST['acf']['luc_nham'];  // 'luc_nham' is an array fields i need to get
    }
    
    add_action('acf/save_post', 'my_acf_save_post', 1);
    
    function tess_fields()
    {
        $id = get_the_ID();
        $fields = my_acf_save_post($id);
        var_dump($fields);
    }
    
    add_shortcode('tess', 'tess_fields');

    Then i try to edit some fileds in a post, but alway return null. I dont know exactly i need to do. Can you help me an clearn example.

    Many thanks!

Viewing 5 posts - 1 through 5 (of 5 total)