Create new post WordPress programmatically with custom meta fields

How can you create and insert new posts containing already filled Advanced Custom Fields programmatically into your database?

  1. Say you have an ACF group with 3 fields each of a different type
    • description (type Text)
    • image (type Image)
    • categories (type Taxonomy)
  2. prepare a basic post

  1. insert post and keep the created post id

  1. then update values of custom fields using the post id

… Or it can be done using the following code:

To enter a new post for a custom type

 

After inserting the post, a post id will be returned by the above function. Now if you want to enter any post meta information w.r.t this post then following code snippet can be used.


Also published on Medium.

Leave a Reply

avatar
  Subscribe  
Notify of