1. Query for posts using the WordPress REST API:
$.ajax({
    url: '/wp-json/wp/v2/posts',
    method: 'GET',
    dataType: 'json',
    success: function(data) {
        console.log(data);
    }
});
  1. Create a new post using the WordPress REST API:
$.ajax({

url: '/wp-json/wp/v2/posts',

    method: 'POST',

    data: {

        title: 'My New Post',

        content: 'This is the content of my new post',

        status: 'publish'

    },

beforeSend: function(xhr) {

xhr.setRequestHeader('X-WP-Nonce', wpApiSettings.nonce);

    },

    success: function(response) {

        console.log(response);

    }

});
  1. Update a post using the WordPress REST API:
$.ajax({

url: '/wp-json/wp/v2/posts/123',

    method: 'POST',

    data: {

        title: 'Updated Post Title',

        content: 'This is the updated content of my post',

        status: 'publish'

    },

beforeSend: function(xhr) {

xhr.setRequestHeader('X-WP-Nonce', wpApiSettings.nonce);

    },

    success: function(response) {

        console.log(response);

    }

});
  1. Delete a post using the WordPress REST API:
$.ajax({

url: '/wp-json/wp/v2/posts/123',

    method: 'DELETE',

beforeSend: function(xhr) {

xhr.setRequestHeader('X-WP-Nonce', wpApiSettings.nonce);

    },

    success: function(response) {

        console.log(response);

    }

});

Categorized in: