Questions tagged [rest-api]

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

Filter by
Sorted by
Tagged with
39
votes
4answers
40k 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 ...
32
votes
8answers
26k 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/...
24
votes
1answer
27k 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 ...
23
votes
4answers
57k 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 ...
21
votes
6answers
9k 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 ...
21
votes
1answer
479 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 ...
20
votes
2answers
29k 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 ...
19
votes
1answer
5k views

Using the Rewrite API to Construct a RESTful URL

I'm trying to generate rewrite rules for a RESTful API. I just want to see if there is a better way to make this work than having to write out every possible rewrite combination. Ok so I have 4 ...
18
votes
3answers
21k 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,...
18
votes
5answers
26k 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 ...
17
votes
2answers
17k 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' => ...
17
votes
7answers
959 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 ...
15
votes
4answers
10k views

SSO / authentication integration with external 'directory service'

I'm about to start working on a prototype for a client - and one of the required features is integration with an in-house user authentication / registration system. This system will act as the ...
14
votes
5answers
12k 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
3answers
23k 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[...
13
votes
8answers
30k 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 ...
12
votes
4answers
24k 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 ...
12
votes
4answers
9k 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 ...
12
votes
3answers
7k 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 ...
11
votes
5answers
23k 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\...
11
votes
2answers
24k views

Add media with WP-Rest-API v2

I need your help to upload a media image in my wordpress blog via the Wp-rest-api v2 and Oauth2 authentication. I did not find in the REST API documentation the way to send my image data (name of ...
10
votes
3answers
6k 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 ...
10
votes
3answers
14k views

Building a custom REST API

I have a WordPress.org site which takes user input, searches a custom database and displays the results of the query. I have this working using the wpdb class. Now I'm trying to get this working for ...
10
votes
4answers
7k views

How to add category to: 'wp-admin/post-new.php'?

I want to have a link to create a new post that sets the category also. I have tried wp-admin/post-new.php?post_category=12 and wp-admin/post-new.php?cat=12, but neither worked. I also tried using ...
10
votes
2answers
5k 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 ...
10
votes
2answers
8k views

Query WP REST API v2 by multiple meta keys

Using v2 of the REST API, I'm wanting to query some posts by multiple meta keys. With v1 I was able to format the url like &filter[meta_value][month]=12&[meta_value][year]=2015 and it worked (...
10
votes
1answer
522 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
1answer
7k views

How to remove rest api link: in http headers?

i would like to remove the "link:" line added to the http headers since wordpress 4.4 here is a curl -I killcandida.org here is the output extract of the line that i would like to delete: Link: &...
9
votes
3answers
7k 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'...
9
votes
2answers
36k 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 ...
8
votes
2answers
6k 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
1answer
8k 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 ...
8
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 (...
8
votes
1answer
8k 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 '...
8
votes
2answers
2k views

Using Backbone with the WordPress AJAX API

I'm attempting to build out a simple TODO plugin using Backbone and have run into an issue with the AJAX API. In order to get the correct AJAX call back you have to pass in the "action" parameter ...
8
votes
3answers
6k 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 ...
7
votes
4answers
13k 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( ...
7
votes
2answers
5k views

WP JSON REST API (Ryan McCue) how to query posts with specific meta data with 'AND' relation?

I use Wp_query class to query my posts. 15 posts are in a template fetched on page load and their filtering works fine. Infinity scroll fetches for other posts using JSON restful services. The filter ...
7
votes
1answer
1k 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 (...
7
votes
2answers
15k 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/...
7
votes
2answers
2k 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
2answers
13k views

WP REST API — How to change HTTP Response status code?

I have a custom endpoint where I want to change HTTP response status to 404 in certain scenarios (e.g post does not exist). How can I do that? Here is an example of custom endpoint: function ...
6
votes
4answers
5k 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?
6
votes
1answer
5k 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 ...
6
votes
4answers
2k 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-...
6
votes
2answers
4k 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 ...
6
votes
1answer
4k 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
2answers
8k views

How would I add custom tables/endpoints to the WP REST API?

I have created custom tables for performance reasons for products, carts, and notifications. I want to make these tables and their data available for normal CRUD via the WP REST API v2. How would I ...
6
votes
1answer
8k 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 ...
6
votes
1answer
2k 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 ...

1
2 3 4 5
22