Home > other >  Do not update specific custom field on save_post in WordPress
Do not update specific custom field on save_post in WordPress

Time:01-03

As several fields are updated programmatically, I want those not to be updated when a post is saved or updated inside the wp-admin dashboard.

For example, the ACF repeater field named tickets must not be saved during backend editing and when the post is saved or updated (because entries that are added programmatically during the time the post is edited are deleted when saved).

Sorry – I have no idea how to implement this.

I know that you rightfully ask for the own approaches and attempts at solutions. Unfortunately, I don't have any. I don't have any ideas. That's why I would be all the more grateful for your help and support.

Thank you so much!

CodePudding user response:

I had a scenario similar to this where I didn't want users to be able to manually update fields. I created a function that would let me use an ACF filter to disable the specific fields. It looked like this:

function vgs_set_acf_fields_to_disabled( $field ) {
    global $post;

    if ( isset( $post ) ) {
        $field['disabled'] = 1;
    }
    return $field;
}
add_filter( 'acf/load_field/name=tickets', 'vgs_set_acf_fields_to_disabled' );

Then, if you have more fields, you can add more add_filter lines and simply update the name variable to match your ACF field name.

Maybe this will work for you as well?

CodePudding user response:

To stop a specific field from being updated when a post is saved or updated in the WordPress backend, you can use the update_field function from the Advanced Custom Fields (ACF) plugin and set the $format_value parameter to false.

Update the value of the 'tickets' ACF repeater field, but do not format the value update_field( 'tickets', $new_value, $post_id, false );

  • Related