WordPress REST API Tutorial (Real Examples)

WordPress REST API Tutorial (Real Examples)

Let’s learn about the new WordPress REST API.

Link to my website:

My HTML & CSS Course:

My “Get a Developer Job” course:

Starter AJAX Code:

Starter Form HTML & CSS:

Link to download zip of finished theme files:

Add me on Twitter for webDev resources and cat pics:


12 Replies to “WordPress REST API Tutorial (Real Examples)”

  1. My code not working .. please help me anyone

    (function( $ ) {
    “use strict”;

    var quickAddButton = document.querySelector(“#quick-add-button”);

    quickAddButton.addEventListener(“click”, function(){

    var ourPostData = {
    “title”: document.querySelector(‘.admin-quick-add [name=”title”]’).value,
    “content”: document.querySelector(‘.admin-quick-add [name=”content”]’).value,
    “status”: “publish”

    var createPost = new XMLHttpRequest();
    var magicalData=”;
    createPost.open(“POST”, “http://localhost/wordpress/wp-json/wp/v2/posts”);
    createPost.setRequestHeader(“X-WP-Nonce”, magicalData.nonce);
    createPost.setRequestHeader(“Content-type”, “application/json;charset=UTF-8″);
    createPost.onreadystatechange = function(){
    if(createPost.readyState == 4){
    if(createPost.status == 201){
    document.querySelector(‘.admin-quick-add [name=”title”]’).value=”;
    document.querySelector(‘.admin-quick-add [name=”content”]’).value=”;
    alert(“Error- Try Again”);
    })( jQuery );

    //function.php code

    wp_enqueue_script(‘cus-main’, get_theme_file_uri( ‘/assets/js/cus-main.js’ ), array( ‘jquery’ ), ‘1.0’, true );

    wp_localize_script( ‘cus-main’, ‘magicalData’, array(
    ‘nonce’ => wp_create_nonce(‘wp_reset’)

    //Html code

    Quick Add post

    Create post

  2. What would be a better tutorial is how to sign in the user from maybe something like a cordova app? otherwise the wp api is useless

  3. hello nice tutorial,
    my question is “how to retrieve more then 10 posts??”

  4. i am not getting wp-json folder. Showing incorrect path. any idea?

  5. Congrats Sir! Crossed 100k subscriber’s just now? Hope to see you making new tutorials soon 🙂

  6. You have a gift. I’ve been designing for about 5 years but recently started leaerning the JS stuff and I read lots of tutorials and also watch lots of videos but your videos stand out. You provide just the right amount of information and explain things in a very clear succinct way but are very thorough. Hard to explain, please keep it up.

  7. thanks for replying
    i would like to know all parameters like per_page, category etc,..
    than can used with url

  8. I love your teaching style. Perfect!!! Thanx for posting these vids!

  9. Brad, do you have or will you do ANY tutorials on PHP? I bought your course on Web Dev with NodeJS, but it seems that there are countless jobs with PHP and not near as many openings with NodeJS? Thoughts?

Comments are closed.