Home › Forums › General Issues › Understanding the ACF database values
Hello and thanks for your time. I’m running WP 5.0.2 with the latest version of ACF Pro and am having trouble understanding the database values generated from ACF. Here’s my scenario:
I have an older site with lots of Posts and I built a new Theme that will instead use Custom Post Types and Custom Taxonomies with some ACF fields. For example:
My original thought with updating the many, many old Posts to this new data structure was to export the CSV, edit/add table columns, then re-import. However, what’s confusing me is I did a quick export and the ACF data is very odd looking.
For example, I expected each new Post to have a single data base row with the typical columns for wp_post_date, wp_post_title, etc., plus new columns for my custom taxonomies and ACF fields.
However, instead, I’m seeing multiple rows for a single new Post and the wp_post_content looks odd. Here’s an example for the Player URL field:
a:7:{s:4:"type";s:3:"url";s:12:"instructions";s:0:"";s:8:"required";i:0;s:17:"conditional_logic";i:0;s:7:"wrapper";a:3:{s:5:"width";s:0:"";s:5:"class";s:0:"";s:2:"id";s:0:"";}s:13:"default_value";s:0:"";s:11:"placeholder";s:0:"";}
I’m really confused by this and searching for ideas on how to update my old Posts to the new data structure mentioned above. Any feedback is greatly appreciated!
I’m not sure where to start with an explanation so I will start with the code that you posted. This is a post for an acf field. This is a URL type of field. ACF stores the field definition as a serialized array in the post_content field.
The post type of this post is probably “acf-field”
This field will be displayed in a field group or as a sub field in some type or repeater stucture. This is determined by the post_parent in the database. This will be the ID of either another “acf-field” post or an “acf-field-group” post.
Beyond this, ACF stores the values of the fields on each post in the _postmeta table.
Thanks, John. I realize now my question may be too convoluted to answer without more details. However, I was able to solve some issues by using a couple plugins to convert my old post types and taxonomies.
The final issues remaining are:
How can I update my old Posts to use their existing Featured Images as the value for a new ACF File field I created for all Posts. I have thousands of Posts that already have a Featured Image, now I just need to update the database so those same image attachments are applied to my new ACF File field.
Additionally, the old database had a column for player names (it was a WordPress custom field). I need all those values to now be migrated to my new Player Taxonomy. This is less of an ACF question and more related to updating values in the database.
The easiest solution to the featured image issue is to change the field name of the ACF field to _thumbnail_id
. However, you’ll still need to use the featured image functions in ACF for these fields until you manually update the post. It’s not a great solution.
The reason it will not work is that the acf field key reference will be missing. Every field in the postmeta table for an acf field has a matching field key reference.
post_id = post ID of the post the field is for
meta_name = "_($meta_name)" = the field name with an _ at the beginning. Following my above advice would mean "__thumbnail_id"
meta_value = The field key of the acf field, example: field_1235676
There is no easy way to do the second part. ACF will store a term ID. WP stores them as terms.
The topic ‘Understanding the ACF database values’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.