Support

Account

Home Forums Backend Issues (wp-admin) Add into admin column for post number's of updated from ACF Select Box

Solved

Add into admin column for post number's of updated from ACF Select Box

  • Hi i have add into my post type “orders” a select with 4 choices.

    When someone is writting through our form, it is creating a new post type with the default select (select value1).

    When an admin is adding info into the post type that is a private post he is selecting an another choices for example (select value2, select value3, select value4) then save it.

    I want to display into the admin wordpress the numbers that the post has been changed.

    For example:

    I change the status to select value2 then i save. I return 2 days later and i change the select to value4 and save it. We will see into then admin colum “Numbers Change” : 2

    A plus will be to be able to get the timestamp between those changed.

    Is it possible i’m kind lost. Thanks you very much for your help.

  • I think i my found a solution. I have activate post revision for my post type.

    But now i only want that revision is saved if this acf field is changed and saved.

    Any idea ?

    Thanks in advance

  • Hi @debosseta

    If you want to use post revision, I suggest you get in touch with WordPress community instead for better support.

    Another method would be using a number field that will hold the total count. Then you can update the total count by using the acf/save_post hook like this:

    function my_acf_save_post( $post_id ) {
        
        if( get_post_type($post_id) == 'orders' ){
            
            // Set the required field name and keys
            $select_field_name = 'select_field_name';
            $select_field_key = 'field_1234567890abc';
            $number_field_name = 'number_field_name';
            $number_field_key = 'field_abcdefghij123';
            
            // Get the old data from database and the new data (posted data)
            $old_select_value = get_field($select_field_name, $post_id);
            $new_select_value = $_POST[$select_field_key];
            
            // If the value changed
            if( $old_select_value != $new_select_value ){
                
                // Get the total count from the database
                $old_count = get_field($number_field_name, $post_id);
                
                // Change the posted data to make sure it's correct
                // This will be saved automatically later
                $_POST[$number_field_key] = $old_count + 1;
            }
            
        }
        
    }
    
    // run before ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 1);

    You can also disable the field by using CSS so the value can’t be edited from the backend.

    If you want to have timestamps, I suggest you use the repeater field instead.

    I hope this helps 🙂

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

You must be logged in to reply to this topic.