Create new Post and populate ACF fields
-
Hi,
I’ve got a Powershell script set up to create a new post in WordPress (which works just fine) using WP REST API (2.0-beta13.1). At the same time as creating posts, I’d like to get custom fields populated with data.
Below is an excerpt of the test script
$content = @{ title='status-123456789' status='publish' content='test' categories=@('22') } $json = $content | ConvertTo-Json Invoke-RestMethod -Uri $uri -Method Post -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -ContentType "application/json" -Body $json
As mentioned, this posts fine to my dev WordPress install.
I’m pretty new to all things JSON/RESTful so would appreciate assistance on populating the ACF fields when creating a new post.
So far, I have read that to populate ACF, I need to use a different endpoint – would I then essentially need to make two requests, first to post using the standard endpoint, then to get the post ID from the response and update that ID with the ACF endpoint? Or can I do it in one request?
Again, very new to this so as much detail as possible would be great.
Thanks
- The topic ‘Create new Post and populate ACF fields’ is closed to new replies.