$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>javascript - Wordpress Rest API|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Wordpress Rest API

matteradmin9PV0评论

I'm trying to call a post from a Wordpress install using WP REST API. I keep getting an error in return and I can't find out why. Do I need to authenticate? One website said I don't need to authenticate for a GET request. WP REST API: Version 2.0-beta9. Here is the code I am using:

$(document).ready(function () {

setTimeout(GetPosts, 2000);

function GetPosts() {

     $.ajax({
        url: '',
        data: {
            filter: {
            'posts_per_page': 1
            }
        },
        dataType: 'json',
        type: 'GET',
        success: function(data) {
            console.log(data);
        },
        error: function() {
            console.log('error');
        }
    });

}

})

I'm trying to call a post from a Wordpress install using WP REST API. I keep getting an error in return and I can't find out why. Do I need to authenticate? One website said I don't need to authenticate for a GET request. WP REST API: Version 2.0-beta9. Here is the code I am using:

$(document).ready(function () {

setTimeout(GetPosts, 2000);

function GetPosts() {

     $.ajax({
        url: 'http://easterly.haamap/wp-json/posts',
        data: {
            filter: {
            'posts_per_page': 1
            }
        },
        dataType: 'json',
        type: 'GET',
        success: function(data) {
            console.log(data);
        },
        error: function() {
            console.log('error');
        }
    });

}

})
Share Improve this question edited Dec 24, 2015 at 9:25 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Dec 23, 2015 at 14:26 The HawkThe Hawk 1696 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 4

What version of the REST API are you using? If you're using the version that's bundled with WordPress 4.4 (ie, v2), you'll need to change your url to something like http://example/wp-json/wp/v2/posts.

Reference

WP API version 2 docs

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far