S
S
serega 20702020-07-22 18:48:26
RESTful API
serega 2070, 2020-07-22 18:48:26

How to update acf field in post revision?

Hey! pliz tell me how to update the custom field in the revision of the post?

The fact is that I update the post through the wordpress rest api with the following post request:

$('.edit_document').on('click', function(e) {
    e.preventDefault();    
    let title_form = $('#title')[0].value  
    let content_form = $('#body-edit')[0].value
    let version_form = $('#version')[0].placeholder
    let status_doc = "publish"        
    let ver = String((Number(version_form) + 0.1).toFixed(1))        
    
    $.ajax({              
        url: REST_API_data.root + 'wp/v2/posts/'+doc_id,
        method: 'POST',
        beforeSend : function ( xhr ) {
            xhr.setRequestHeader( 'X-WP-Nonce', REST_API_data.nonce );
        },           
        data: {
            'title': title_form,
            'content': content_form,
            'status': status_doc,
            'fields': {
                'version': ver,
            }
        },
        success: function(d) {
            console.log(d);
        },
        error: function(d) {
            console.log(d);
        }
    })
})


after which all fields are updated in the post and the custom version field too, but in the post revision ( localhost/wp-json/wp/v2/posts/id_post/revisions

) the version field becomes NULL the required version is displayed in the revision of the post

Tell me where to dig who can come across? I can't figure out the reason at all

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question