Skip to content

Instantly share code, notes, and snippets.

@adamcrampton
Forked from PurpleBooth/README-Template.md
Last active July 2, 2019 22:49
Show Gist options
  • Save adamcrampton/4a30c3d8ee63dd6e2538a10679d732be to your computer and use it in GitHub Desktop.
Save adamcrampton/4a30c3d8ee63dd6e2538a10679d732be to your computer and use it in GitHub Desktop.
ACF field values for WordPress wp_posts table

Manual Insertion of ACF Fields Into The WordPress Database

To add ACF fields to the WordPress database (e.g. when using a seeder), you need to add each ACF field as a row into the wp_posts table using the post_type value of acf-field.

This guide assumes that you have defined the fields with PHP and are seeding posts directly into the WordPress database.

Note: You can also create ACF Groups in a similar way using acf-field-group post_type. I will cover this in a separate gist.

Getting Started

Note: The only practical use case for this is a database seeder (e.g. for demo data) - any other interaction with ACF and the WordPress database should really be done via the plugin itself.

Ensure that you have already done the following before inserting these values:

  • Registered any Custom Post Types
  • Registered ACF Groups and Fields (with PHP)
  • Inserted your actual posts to the database
  • Linked any required postmeta to your posts

Column Values

The values required for each row are as follows:

Note: The post_content column is optional, as the field configuration has already been defined via PHP, as mentioned above. For the sake of completeness, I have included the details anyway.

  • post_author: Your author ID should be fine
  • post_date: Generate current local timestamp
  • post_date_gmt: Generate current GMT timestamp
  • post_content: A serialized array containing data for these key:value pairs:
    • type
    • instructions
    • required
    • conditional_logic
    • wrapper (nested array)
    • default_value
    • placeholder
    • prepend
    • append
    • maxlength
  • post_title: Arbitrary name for the field
  • post_excerpt: The field name (not prefixed with field_)
  • post_status: publish
  • comment_status: closed
  • ping_status: closed
  • post_password: ""
  • post_name: field name prefixed with field_ (e.g field_paragraph)
  • to_ping: ""
  • pinged: ""
  • post_modified: Generate current GMT timestamp
  • post_modified_gmg: Generate current GMT timestamp
  • post_content_filtered: ""
  • post_parent: 0
  • guid: ''
  • menu_order: 0
  • post_type: acf-field
  • post_mime_type: ""
  • comment_count: 0

For further info on ACF values for the post_content field, see: https://www.advancedcustomfields.com/resources/register-fields-via-php/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment