Support

Account

Home Forums Backend Issues (wp-admin) Can I safely delete the field references in post_meta?

Solving

Can I safely delete the field references in post_meta?

  • Hello,

    ACF is storing a “reference” for each field and value within post meta.
    → This means there are 2 entries for each meta value…

    Problem

    * ACF is a power tool, and when you start using it, you will always use it.
    * But it generates unnecessary, superfluous and redundant information

    We have a project with ~3 million entries in post meta, of this ~ 700,000 are these references…

    Question: Can I safely delete these values, if I don’t need them (render fields without ACF)?

    —————-

    What is the reference good for?

    → It is used to get the field type and render it “correctly”

    Proposal

    → have a filter to disable the storage (possibly don’t store it that way)
    → use some more smart way to find the field type
    → In know, same key could be different type
    → but there always should be a “unique” matching field configuration anyway, as it should be a problem having two fields on one view with the same key, but different types.

  • The answer is no. Without the field key reference not only does ACF not know what type of field it is but ACF will not return the field if the field key reference in the DB is missing when using one of the ACF template functions. The latter part was added for security to prevent the use of fields created outside of ACF.

    The issue and reason that the field key reference is needed is do to the simplicity of the WP meta tables. There are only 3 usable columns: post_id, meta_key, meta_value. There simply isn’t a way to relate a field to this data without the additional value.

    This is also due to the fact that field names do not need to be unique. You could easily have two fields used on two different post types that are different types of fields with the same name. But the field key is always unique. ACF uses a combination of the post ID and the field name to get the field key reference used for the specific field name used on the specific post.

    It is possible to bypass the use of the field key reference by using the field key in ACF template functions instead of the field name. Using the field name is provided as a convenience to developers to make it easier for coding and for code clarity. It is easier to use something like “background_color” and it is easier to see what that field is for instead of something like “field_XXXXXXX”.

    use some more smart way to find the field type

    ACF was built to work with what is provided by WP, it is basically a big wrapper for all of the meta and option functions in WP and does nothing that could not be accomplished without it. What ACF does is that it makes the building out of complex admin UIs simple and fast saving the developer the need to code it all themselves. You can even replace all of the ACF template function calls with native WP function calls, provided you also want to do all of the field value formatting yourself.

    I’m sure that if anyone came up with something simpler that also worked within what is provided natively in WP that the developers would love to hear about it.

  • Hello John,

    Thanks for your answer.

    I just implemented a job and filter to remove these values from the DB (experimental), as we don’t use ACF methods for rendering, only for the backend masks. Looks good so far…

    use some more smart way to find the field type

    I’m sure this should be possible. Please correct me if I’m wrong.

    The same rules, that render a meta box in the backend, could apply to finding the correct field type for a DB meta_key.

    Even if ACF supports the same meta_key with different types, there still only can be one of these used per DB post.

    I.e. you can not create a

    • Field: my_field as “numeric” for post and
    • Field: my_field as “email” for post at the same time

    ACF allows this, but WordPress post_meta architecture not… one field just replaces the other

  • I’m not the developer so I’m just stating what I know from years (many) of using ACF.

    Is it possible to use the same code to find a field as it is for displaying field groups in the admin?

    Showing field groups in the admin is based on the field group, not the individual fields, this is top down, not bottom up. The only way to know if a field is shown is to know if the field group should be shown.

    Is it possible to find a field for a post in the same way? Yes, here is what would be involved.

    1. Get all of the field groups that can be shown based on the post ID.
    2. Loop over each field group and then all of the fields in in each group until a matching field name is found.

    It would have to be repeated for every field.
    This process would be extremely inefficient at scale.

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

You must be logged in to reply to this topic.