WordPress REST API (wp-api) 404 Error: Cannot access the WordPress REST API

UPDATED NEW WAY

I also faced similar problem in a local project. I used index.php after my project url and it worked.

http://localhost/myproject/index.php/wp-json/wp/v2/posts

If it displays a 404 error then update permalinks first (see “Paged Navigation Doesn’t Work” section

If it works, maybe you need to enable mod_rewrite, on ubuntu:

a2enmod rewrite
sudo service apache2 restart

Installation

The REST API is included in WordPress 4.7! Plugins are no longer required, just install the latest version of WordPress and you’re ready to go.

If you’re before 4.7:

  1. Download plugin from here: http://v2.wp-api.org/

  2. install and activate it.

Usage

To get all posts:

www.mysite.com/wp-json/wp/v2/posts

For the search functionality, searching for test post looks like this:

/wp-json/wp/v2/posts?filter[s]=test

Leave a Comment