Home Forums Add-ons Flexible Content Field Problems with keys/values in the database


Problems with keys/values in the database

  • I made a method that counts how many times a flexible layout is used on a post. I discovered that some posts had layouts in the database that’s not visible on the post edit screen.

    Is there anyone else that has had the same problems?

    I’m counting the rows in wp_postmeta by meta_key LIKE 'flexiblefield_%_layout'. But right now I can’t trust the result.

    Is the only way to remove all flexible postmeta rows and re-save all layouts to get the correct data in the database?

  • The data can be incorrect if, for example, you have 6 layouts and delete one. The 6th one’s data remains in the database. There isn’t any way to automatically delete ACF data in the database that is no longer used. You’d need to create your own acf/save_post filter and do checking based on your field groups and fields to remove anything that shouldn’t be there.

    You can get an accurate count of the layouts on a site. The meta value 'flexiblefield' holds a serialzed array. If you get all of the meta values under this meta key the total count of all of the arrays will be the total count of all layouts for that flex field.

  • Thank you for explaining 🙂

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

The topic ‘Problems with keys/values in the database’ is closed to new replies.