• Resolved bwdgroup

    (@bwdgroup)


    I just can’t get to POST ACF fields but WP fields are fine.

    My HTML Front-End, my custom ACF field is called model as per the example I have added fields and put the field into bracket.

    <div class="admin-quick-add">
      <h3>Quick Add Post</h3>
      <input type="text" name="title" placeholder="Title">
      <input type="text" name="fields[model]" placeholder="Model">
      <textarea name="content" placeholder="Content"></textarea>
      <button id="quick-add-button">Create Vehicle</button>
    </div>

    I have a Javascript file performing the JSON function this is the snippet to capture the form data.

    	var ourVehicleData = {
    				"title" : document.querySelector('.admin-quick-add [name="title"]').value,
    				"fields[model]" : document.querySelector('.admin-quick-add [name="fields[model]"]').value,
    				"content" : document.querySelector('.admin-quick-add [name="content"]').value,
    				"status" : "publish"
    			}
    
    			var createVehicle = new XMLHttpRequest();
    			createVehicle.open("POST", "https://mywebsiteaddress.com/wp-json/wp/v2/posts");
    			createVehicle.setRequestHeader("X-WP-Nonce", auth_user.nonce);
    			createVehicle.setRequestHeader("Content-Type", "application/json", "charset=UTF-8");
    			createVehicle.send(JSON.stringify(ourVehicleData));
    		});

    – I have request version 3 in the settings.
    – Both custom fields show in rest and can edit in rest.

    Any help on this would be much appreciated.

    Thanks

    • This topic was modified 6 years, 6 months ago by bwdgroup.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Please note that you have requested v3, but in your code
    createVehicle.open("POST", "https://mywebsiteaddress.com/wp-json/wp/v2/posts");
    you refer to v2.
    Hope it helps

    Thread Starter bwdgroup

    (@bwdgroup)

    Thanks, The way point is now

    https://mywebsiteaddress.com/wp-json/wp/v3/posts

    It will post the title and content but ignores the custom field.

    So frustrating.

    Thread Starter bwdgroup

    (@bwdgroup)

    just noticed you cannot create new posts with ACF data but only edit.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Cant get POST [Fields] to Work’ is closed to new replies.