Support

Account

Home Forums ACF PRO Submit data to post type on frontend with ajax

Unread

Submit data to post type on frontend with ajax

  • Hi,

    I want to create new records for a simple custom post type which literally has a title and a year. The title is the standard wordpress title and the year is the advanced custom field. When posting via Ajax and jQuery only the title is stored and the year does not. Is there something obvious I am doing wrong?

    I have the latest paid version of ACF installed.

    $('.submit-qualification').on('click', function (e) {
        e.preventDefault();
        var newQualification = {
            'title': $( '.qualification-title' ).val(),
            'field_5ec63bc5b6fe0': $( '.qualification-year' ).val(),
            'status': 'draft'
        }
        $.ajax({
                url: myData.root_url + '/wp-json/wp/v2/qualification/',
                type: 'POST',
                data: newQualification,
            	beforeSend: (xhr) => {
    			xhr.setRequestHeader('X-WP-Nonce', myData.nonce);
    			},
            })
            .done(function (data) {
                console.log(data);
                alert(newQualification.field_5ec63bc5b6fe0);
            })
            .fail(function (jqXHR, textStatus, errorThrown) {
                console.log(textStatus + ': ' + errorThrown);
                console.warn(jqXHR.responseText);
            });
    })
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.