• First of all I’ve been posted , my question to the ACF support site, WP.stackexchange but all answer is something like “read the plugin doc.”. I know that I have to use THIS but I couldn’t understand the info from the plugin’s documentation and don’t know how to implement it with my function.

    Here it is my problem:

    I have a function that relay on acf checkbox field. It is working fine but I have to update the post twice, because get_field(‘checkbox_field’) returns the data after the other content. Example:

    add_filter('wp_insert_post_data', 'my_func');
    function my_func($post) {
        $pageID = 123; // certain page id
        $cp_field = get_field("custom_field", $pageID);
        if ($post['post_type'] != 'my_post_type'
            || $post['post_status'] == 'trash'
        )
            return $post;
    
        if(!get_field('checkbox_field')) { // The problem field
            // ... do something here
            return $post;
        } else {
            return $post;
        }
    }

    In short: I want when I do the check in get_field(‘checkbox_field’) to get it’s value before saving the post.

    My last hope is in you guys. Thanks and sorry for my bad English.

The topic ‘Get ACF fields value before saving’ is closed to new replies.