node-wpapi icon indicating copy to clipboard operation
node-wpapi copied to clipboard

Unable to create post with ACF field values

Open shanmuganathan-balaraman opened this issue 8 years ago • 10 comments

Hi, Thanks for this wonderful API,

I am trying to create post with ACF field values, but API creates the post with title and content only and skips the ACF field values. Event I tried to update the ACF field value it throws following error

{ 
code: 'cant_update_item',
  message: 'Cannot update item',
  data: { status: 500 }
 }

I referred the #176 as well

Find the code snippet below screen shot 2017-10-10 at 9 09 24 am

Someone help to sort out this. Sample code will be more helpful. Thanks in advance.

im using this wonderful api to update my products too , u can update your acf fields this way , after registering your endpoint for example

wp.productsAPI = wp.registerRoute("wp/v2", "/products/");

this code snippet will create a new post that support acf fields

wp
  .productsAPI()
  .create({
    title: "Post number",
    fields: {
      product_name: "product name",
      product_description: "product description",
       categories: [
        { category_name: "category1" },
        { category_name: "category2" }
      ]
    },
    status: "publish"
  })

elements under fields are the acf fields , and categories is a repeater field :)

gallaouim avatar Nov 15 '17 11:11 gallaouim

I had exactly the same issue, thank you @gallaouim this worked for me!!

donnierisk avatar Dec 21 '17 14:12 donnierisk

@gallaouim Does it also apply to regular post type created by CPT UI?

fkiller avatar Feb 19 '18 21:02 fkiller

@fkiller im sorry for the late answer but yes it apply to regular post type created by CPT UI

gallaouim avatar Oct 24 '18 13:10 gallaouim

@gallaouim, @donnierisk I can't get your code to post data to acf fields when updating a post. Are you guys using the ACF to REST API plugin to register the routes for the fields?

peter-mumford avatar Feb 25 '19 13:02 peter-mumford

Hi @peter-mumford Yes I did use that. I don't have the code anymore to check it exactly unfortunately

donnierisk avatar Feb 27 '19 07:02 donnierisk

When you make an update / create request with WP API you use the word fields instead of acf

DanielRSnell avatar Oct 05 '19 07:10 DanielRSnell

I've implemented this solution as written above by @gallaouim, but it didn't work (custom post is created successfully, but no ACF data is available in it after creation). I have a custom route registered and have used the fields property with an object containing my custom fields to create the custom post via the REST API.

Has anyone seen any changes to this recently that might have affected this solution? Is this approach still working for others?

kmaida avatar Jun 28 '20 03:06 kmaida

I've implemented this solution as written above by @gallaouim, but it didn't work (custom post is created successfully, but no ACF data is available in it after creation). I have a custom route registered and have used the fields property with an object containing my custom fields to create the custom post via the REST API.

Has anyone seen any changes to this recently that might have affected this solution? Is this approach still working for others?

Exactly the same problem here. Did you ever figure this out?

neptunus avatar Nov 16 '20 13:11 neptunus

I'm having this same problem as well. I created a new custom Post Type called "signup" and directed the acf fields to that. I registered the route using:

wp.signups = wp.registerRoute("wp/v2", "/signups/");

Then used the 'fields' key but to no avail.

wp .signups() .create({ title: "Chuck Norris", content: "I am cookin up some good food", categories: [188], fields: { name_provider: name, meal_provider: meal, date_provider: date, }, status: "publish", })

I also tried the 'acf' key and that didn't work either

wp .signups() .create({ title: "Chuck Norris", content: "I am cookin up some good food", categories: [188], acf: { name_provider: name, meal_provider: meal, date_provider: date, }, status: "publish", })

The acf fields are not updating.

bsartain avatar Jul 13 '22 15:07 bsartain