• Hi everybody,

    I have a website where I allow subscribers to create posts (custom post) in the frontend.
    To do that, I’m using Ajax post request and everything is running well for “Title” or “content”, nevertheless, for custom fields created using ACF, I have been struggling.

    I have been trying to find a solution, but it has been hard to find it.

    Bellow is a portion of my “create post request”.
    “raw_material” is my custom field created in the ACF.

    Can you help?
    Thank you.
    Nuno Silva.

    createQuote(e) {
        var ourNewPost = {
          'title': $(".new-quote-title").val(),
          'content': $(".new-quote-body").val(),
          'raw_material': $(".custom-select").val(),
          'status': 'publish'
        }
        
        $.ajax({
          beforeSend: (xhr) => {
            xhr.setRequestHeader('X-WP-Nonce', webData.nonce);
          },
          url: webData.root_url + '/wp-json/wp/v2/quote/',
          type: 'POST',
          data: ourNewPost,
          success: (response) => {
            console.log("Congrats");
            console.log(response);
          },
          error: (response) => {
            console.log("Sorry");
            console.log(response);
          }
        });
      }

The topic ‘Use Custom Fields with Ajax Post request’ is closed to new replies.