Home Forums General Issues Best Practice for Changing Custom Fields


Best Practice for Changing Custom Fields

  • I’m using the Advanced Custom Fields plugin for a project I’m currently working on. From what I understand, ACF stores its values into WordPress’ Custom Fields.

    What I wanted to know is what’s the best way to go about editing and changing these Custom Fields after I’ve already defined them??

    Obviously, I’d like to get my naming conventions right the first time, but sometimes I’m forced to make a change.

    P.S. Is there a way to flush the Custom Fields that are no longer being used by Advanced Custom Fields. An easier way to delete them instead of going into every post type and deleting the Custom Fields manually, perhaps?

    Any help is appreciated. Thanks in advance!

  • Hi @realph

    Flush values:

    The best way is to edit the field and change the field name. Next, access your DB via phpMyAdmin and write some SQL to look for the old field_name and replace it with the new field_name.

    The field name will bi found multiple times in the wp_postmeta table in the meta_name column.

    For each row in the wp_postmeta table, there is a second row containing a ‘reference’ from the value to the field object. This looks like an underscored version.

    So, to change both the field_name and the reference rows, you would write something like this:

    UPDATE wp_postmeta
    SET meta_key = 'new_field_name'
    WHERE meta_key = 'old_field_name';


    UPDATE wp_postmeta
    SET meta_key = '_new_field_name'
    WHERE meta_key = '_old_field_name';

    Hope that helps


  • I was dreading someone would point me to my database and assumed it would probably be the sure-fire way of doing this.

    Oh well, at least I know those field names will be gone for good if I do it via the phpMyAdmin panel.

    Thanks again!

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

The topic ‘Best Practice for Changing Custom Fields’ is closed to new replies.