Questions tagged [rest-api]

Questions about the core RESTful HTTP API for accessing WP content and data.

Filter by
Sorted by
Tagged with
28
votes
4answers
27k views

Is the Wordpress REST API installed and enabled in a vanilla Wordpress 4.7 installation?

I've just installed Wordpress 4.7. One of the mentions in the announcement is that it features a REST API. My understanding is: The Wordpress REST API plugin is not needed anymore, because ...
28
votes
4answers
18k views

WordPress 4.7.1 REST API still exposing users

I have upgraded my WordPress to 4.7.1, and after that I've tried to enumerate users through REST API, which should be fixed, but I was able to retrieve users. https://mywebsite.com/wp-json/wp/v2/...
20
votes
1answer
457 views

With Rest V2 (WP4.7) how does one restrict certain RESTFUL verbs?

I am aiming to restrict certain RESTUL verbs per custom post type. For example, given a Vocabulary custom post type, I would like to say: Permission Matrix +-------+---+----------+ |index | X | GET ...
18
votes
4answers
42k views

How to use OAuth authentication with REST API via CURL commands?

I am trying to use the WordPress Rest Api with authentication to get more data from the API. I have installed the Oauth plugin, rest-api plugin, and gotten API credentials from WP-CLI. I have ...
17
votes
7answers
774 views

REST API purpose?

First of all, I understand that this is a plugin at current point but it is most certainly almost part of WordPress anyway. So I hope that this is not getting flagged as off-topic. I've read their ...
14
votes
2answers
15k views

How to: Make JWT-authenticated requests to the Wordpress API

This is not really a question but a guide on how to make authenticated requests to the Wordpress API using JWT. I'm writing this as a reminder to myself and for those who may need some help with the ...
14
votes
4answers
9k views

Filtering multiple custom fields with WP REST API 2

I want to filter posts based on multiple acf custom fields with AND relation. Something like this: $args = array( 'post_type' => 'product', 'meta_query' => array( '...
13
votes
5answers
5k views

Does something like is_rest() exist

I am starting a bit with the REST API. If I am not completly mislead, the init action hook is also executed when its a REST API request. Now, I want to execute some code only, when it is not a REST ...
12
votes
4answers
17k views

Hiding WordPress REST API v2 endpoints from public viewing

I would like to start using the WordPress REST API v2 to query information from my site. I've noticed that when I visit an endpoint URL directly, I can see all of the data publicly. I've also seen ...
12
votes
1answer
16k views

How do you retrieve a post by slug name through REST API?

It works for my pages but not for my posts. If I go to example.com/wp-json/wp/v2/pages?slug=page-name it will retrieve the page correctly. If I go to example.com/wp-json/wp/v2/posts?slug=post-name it ...
12
votes
2answers
9k views

Wordpress Rest API custom endpoint optional param

Is it possible to use register_rest_route() with optional parameters in url? Let's say route is registered this way: register_rest_route( 'api', '/animals/(?P<id>\d+)', [ 'methods' => ...
11
votes
2answers
12k views

WP Rest API: details of latest post including featured media url in one request?

I'm using wp-rest api to get posts information. I also use wp rest api filter items to filter fields and summarize the result: When I call http://example.com/wp-json/wp/v2/posts?items=id,title,...
10
votes
5answers
18k views

WP REST API: filter by category 1 AND category 2

I have been meddling with REST API and I am stuck with this: How can I filter posts in both cat1 and cat2? For now, ?categories[]=45&categories[]=50 returns in category ID 45 OR 50 - how can I ...
10
votes
1answer
440 views

run silex or slim with wordpress

I am running a theme on WordPress. In this theme, I am making some AJAX calls where I am expecting some response. (http://example.com/capis/v0/packages/) To serve above http calls I am using silex ...
9
votes
4answers
15k views

Get post count in wp rest API v2 and get all categories

I want to get the count of my posts. I think use wp-json/wp/v2/categories?page=1 >> count it's a good way to go. But using above solution is not a cup of tea in term of speed and i don't know how to ...
9
votes
3answers
16k views

How to get custom post meta using REST API

I am trying to create a REST APIs for my wordpress website which is used for facility listing using wordpress job manager plugin. I have registered my custom post , taxonomies in \plugins\rest-api\...
9
votes
3answers
4k views

Nonce retrieved from the REST API is invalid and different from nonce generated in wp_localize_script

For those that arrive from Google: You probably shouldn't get the nonces from the REST API, unless you really know what you're doing. Cookie-based authentication with the REST API is only meant for ...
8
votes
3answers
4k views

Can I use REST-API on plain permalink format?

Recently all of my REST-API requests suddenly turned to return a 404 error, Every request (no matter custom endpoint or built-in). Then I figured it's because of permalink's structure. /wp-json/ is ...
8
votes
3answers
4k views

check the requesting url

Using WP 4.8.2 What is the best way to check the requesting URL when processing a request with the rest-api? For example, a site receives a request and you want to check if it came from an 'allowed'...
8
votes
2answers
4k views

WP REST API Require Password for GET Endpoint

I have a custom post type, card, that I'm exposing through the WP REST API. Is there a way to require authentication, with cookie or Basic Auth header? I see an argument under the POST method block ...
8
votes
2answers
2k views

WP REST API Is it rather easy to rename the default wp-json uri part?

The WP REST API exposes a lot of information so I filter endpoints that aren't needed to expose. I can't filter everything: The location of needed media files are exposed for example. As an extra ...
7
votes
3answers
4k views

wp_get_current_user() function not working in Rest API callback function

Consider the following class. <?php class MCQAcademy_Endpoint extends WP_REST_Controller { /** * Register the routes for the objects of the controller. */ public function ...
7
votes
1answer
2k views

Can a theme be built in React?

Searching on Google and the sites archives under the query React I've found a few interesting questions: Can I upload Wordpress-react theme in Wp theme repository Implementing Isomorphic JavaScript (...
7
votes
2answers
1k views

Is there a way to get protected meta fields through any of the available built-in WordPress APIs? (xmlrpc, wp-json)

WordPress has several APIs build in: XML-RPC REST API by default they don't return custom post types or protected meta keys. I want to access the protected meta fields of a plugin. I tried to ...
6
votes
3answers
12k views

How to do a meta query using REST-API in WordPress 4.7+?

I am trying to filter by a meta query but no matter what I try I can not make it work. Basically I want this query in through the rest API: wp-json/wp/v2/books?meta_query[relation]=OR&meta_query[...
6
votes
1answer
3k views

Wordpress REST API - Permission Callbacks

I'm currently building a small REST API with the WP-REST v2 plugin. Everything is working perfectly fine, however, in the documentation there are permission callbacks, which restrict access to certain ...
6
votes
1answer
722 views

Does WP REST API have a built in route for calling menu?

Upon my research the latest question I was able to reference referred to the WP REST API plugin before it was built into core. The best answer on the question referred to building a custom endpoint (...
6
votes
1answer
5k views

Getting user meta data from WP REST API

I am working on a project using the WordPress REST API and VueJS along with Axios (for the AJAX calls to GET/POST data back to the site). However, i need to be able to access a user's meta data ie '...
6
votes
1answer
2k views

Update CPT meta data using REST API

I'm trying to update a CPT post's metadata using the REST API. I can update a numeric metadata element using a POST such as this: example.com/wp-json/wp/v2/posts/73/meta/229?value=2 This method is ...
6
votes
1answer
10k views

WP REST API no longer supports filter param, so how do I get posts in a custom taxonomy?

All around the Interwebs I see advice from people who say that when you want to get posts in a custom taxonomy you should use the filter parameter, for example: https://example.com/wp-json/wp/v2/...
6
votes
1answer
1k views

WP REST API create post authentication issue

I am getting a 401 or 403 error when trying to create a post from front end. I am using angular in the front end and I want to use basic authorization. I have enqueued the api and created the nonce: ...
6
votes
1answer
440 views

Edit srcset and sizes attributes in Gutenberg image, cover and gallery - blocks

I am looking for a way to adress the responsive srcset and sizes attributes on Gutenberg image blocks - like image, cover and gallery. Usually one would do this with the '...
6
votes
3answers
4k views

How do I cache (core) API requests?

I'm am currently trialling the new (as of 2017) core API built into Wordpress. My setup is reasonably simple: +---------+ +------+ +---------+ |Wordpress|<-->|Guzzle|<-->| App ...
5
votes
2answers
21k views

How to use WP-REST API to login user and get user data for Android app?

I want to use Wordpress REST API to Login and get user data on android app. I am using wp_users table for user and a custom table for user info . I tried writing my own REST API but i for that i ...
5
votes
3answers
6k views

Custom post types filtered by taxonomy using REST API v2

I have the following situation: I created a custom Post Type names Works. And also attached to it custom taxonomy named Work Types Here is the code function rk_work_post_type(){ $labels = array( ...
5
votes
4answers
1k views

REST API: Backbone and custom endpoint

I'm trying to figure out how I should call a REST API custom endpoint from the JS code of a plugin. Here is the PHP code of a sample plugin I've just written to show my issue. The filename is rest-api-...
5
votes
2answers
2k views

WP-AJAX vs WP REST API: What to use for requests to the website from outside?

I have website on WP. Also I have account in one web service. I need to get a request from this web service to a certain address of my website. This is a webhook that I want to handle with my own ...
5
votes
1answer
3k views

Displaying a page built with Elementor using the REST API [closed]

I'm new to working with the REST API, and I can't seem to wrap my head around this issue. I have several static pages that I created using the Elementor page builder. Since I am trying to integrate ...
5
votes
1answer
4k views

Fetch All Posts (Including Those Using a Custom Post Type) With Wordpress API

With the Wordpress API, we can use the following request to get all posts of the default 'post' type: http://example.com/wp-json/wp/v2/posts Supposing the 'books' and 'movies' custom post types ...
5
votes
1answer
2k views

wp rest api v2 return json_no_route

i am using WP rest API v1 and everything is ok. But now i want taste some WP rest API v2. the problem is, when i cal: mysite.com/wp-json/wp/v2/posts or: mysite.com/wp-json/wp/v2/post or ...
5
votes
1answer
948 views

cURL 28 error after switch from to brew php 7.2 on localhost

I've been running into trouble with all my localhost install of Wordpress reporting cURL error 28 (timeout) since (I believe!)I've switched my PHP version from 7.0 to 7.2 with brew on my local Mac OS ...
5
votes
1answer
947 views

When adding a custom REST endpoint, where do you put the endpoint function, and where do you put the function registration call?

WordPress documentation, bloggers, and StackExchange answerers have done a great job of describing the code you write to make a custom REST endpoint, but I cannot find any documentation that describes ...
5
votes
1answer
633 views

WP-REST API not returning all its endpoints, 404 on documented endpoints

Here's my configuration: WordPress multisite installation on a subdirectory WordPress version is 4.7 Let's say my WordPress site is example.com/mywebsite My WordPress site has published posts The ...
4
votes
2answers
1k views

REST API endpoint for elasticpress autosuggest

The AJAX, which is part of Elasticpress, looks like this $.ajax( { url: epas.endpointUrl, type: 'GET', dataType: 'json', crossDomain: true, data: JSON.stringify( query ) } ); ...
4
votes
2answers
1k views

To Disable Wordpress Rest API or Not To Disable?

I have my blog self hosted running WordPress and I Do NOT need the Wp-Rest API. But as it turns out disabling it is causing to Contact Form 7 To not work. Contact form 7 simply shows the spinning ...
4
votes
2answers
8k views

How do I create a user using the new JSON api in 4.7?

I formerly had the JSON API and JSON USER API plugins working before 4.7 and I have seen the documentation at the ReST API User reference, https://developer.wordpress.org/rest-api/reference/users/#...
4
votes
1answer
1k views

How to return Meta data from the REST API?

I added meta box City and Location to my post, but when I calling the endpoint (by WP Rest API) /wp-json/wp/v2/<post_type>/<post_id> it's not returning my meta data. I tried to use ...
4
votes
4answers
3k views

How do I fetch the static front page using the REST API?

I would like to create an Angular 2 SPA that uses the WordPress REST API as a back-end. How can I use the API to fetch the page the user has set as their front page?
4
votes
2answers
3k views

Why is my custom API endpoint not working?

I tried to include this code in my plug-in php files as well as in functions.php. (In the end I would like it to be in the plug-in's php file but I'm not yet sure if possible, that would probably be ...
4
votes
2answers
6k views

How does REST API cookie authentication work in WP 4.7?

Though I have logged in, I cannot create a post on frontend. WordPress always return 401 Unauthorized response. I have dumped $_COOKIE to make sure logged-in cookie was set and got something like this:...