Support » Plugin: ACF to REST API » How do you update ACF fields in jQuery via dynamic ADJAX requests?

  • I’m trying to create a form where user data is captured via jQuery and sent to my custom field via the REST API in WordPress.

    The HTML

    <input class="new-note-title" placeholder="Title">
             <textarea class="new-note-body" placeholder="Your note here..."></textarea>
             <p>Thought Breakdown Boxs</p>
             <textarea class="breakdown-1" placeholder="A ton of love"></textarea><p class="symbol">+</p>
             <textarea class="breakdown-2" id="broken" placeholder="A possitive environment"></textarea><p class="symbol">=</p>
             <textarea class="breakdown-3" placeholder="An environment for growth"></textarea>
             <button class="submit-note fa fa-blind"> Save Thought</button>

    jQuery Code The purpose here is to grab the text the user just typed and place it into the request

    createNote(e) {
        var theNewPost = { 
                'title': $(".new-note-title").val(),
                'content': $(".new-note-body").val() + $(".breakdown-1").val() + $(".breakdown-2").val() + $(".breakdown-3").val(),
                'acf: lb-1': $(".breakdown-1").val(),
                'acf: lb-2': $(".breakdown-2").val(), //$(".breakdown-2").val(),
                'acf: lb-3': $(".breakdown-3").val(), //$(".breakdown-3").val(),
                'status': 'publish'
          beforeSend: (xhr) => {
            xhr.setRequestHeader('X-WP-Nonce', siteData.nonce);
          url: siteData.root_url + '/wp-json/wp/v2/lesson/',
          type: 'POST',
          data: theNewPost,
          success: (response, theNewPost) => {
            $(".new-note-title, .new-note-body, .breakdown-1, .breakdown-2, .breakdown-3").val(''); // empties everything in the boxes

    In the end all of my ‘title’ and ‘content’ data is transferring correctly and creating that new post successfully….but my custom fields are empty.

  • The topic ‘How do you update ACF fields in jQuery via dynamic ADJAX requests?’ is closed to new replies.