Rewrited question: There is a similar question HERE but I don't know how to combine it with my code.

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.

Here is an 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;

Any help would be greatly appreciated. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.