Questions tagged [rest-api]

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

Filter by
Sorted by
Tagged with
14
votes
4answers
10k 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( '...
17
votes
2answers
19k 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
2answers
14k 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
6answers
6k 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 ...
7
votes
3answers
15k 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[...
8
votes
4answers
5k 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
6k 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 '...
9
votes
4answers
17k 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\...
6
votes
2answers
3k 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
2k 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 ...
2
votes
1answer
1k views

Match REST API post output from custom endpoint

What filters will transform a normal WP_Post object (as returned from get_posts()) to match the post objects returned from native REST API endpoints? I have a custom endpoint which returns a WP_Post ...
1
vote
2answers
159 views

Wordpress Rest filter for custom taxonomy gets applied to the admin area

I have a custom taxonomy called collection, with advanced custom fields in it. I'm using wordpress API, so since I need to filter the API responses by ACF values, I have this filter in my theme ...
2
votes
1answer
7k views

WordPress V2 REST-API: Endpoints 404?

I just installed and activated the latest version of the WP REST API plugin. However, when I attempt to access a REST endpoint, I end up with the Apache 404 page. $ curl -i 'http://example.com/wp-...
18
votes
4answers
47k 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 ...
14
votes
4answers
19k 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 ...
30
votes
4answers
20k 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/...
16
votes
1answer
18k 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 ...
8
votes
2answers
3k 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 ...
5
votes
2answers
17k views

Is it safe to fix Access-Control-Allow-Origin (CORS origin) errors with a php header directive?

I am trying to show a Formidable Pro Form from a WordPress site to the other. I followed the developer's API and the REST API, but faced a CORS problem. Then I found a suggestion on a forum thread ...
3
votes
1answer
14k views

WP REST API “rest_no_route” when trying to update meta

I have been working with the WP REST API and all GET (read) commands pull the data I want from both built in and custom post types (this plugin was a godsend btw to help). I can also POST to create ...
10
votes
3answers
5k 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 ...
2
votes
1answer
199 views

Headless Wordpress: How to authenticate front end requests?

I am envisioning Wordpress on the back end to work with React.js on the front end like this: Wordpress is installed on http://example.com/api React.js script is loaded into http://example.com/index....
2
votes
1answer
3k views

How to Authenticate WP REST API with JWT Authentication using Fetch API

My goal is to send user comments with a POST request from a server-side Lambda function to my WordPress API. I'm using Gatsby and Netlify. When someone leaves a comment in the comment form of my ...
4
votes
2answers
7k 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:...
4
votes
1answer
2k views

Include custom post meta value in fetched JSON

I have a custom post type note and I can easily fetch the posts using WP REST API: http://example.com/wp-json/wp/v2/note Works fine! But in the JSON string, I want it to include the value of custom ...
3
votes
1answer
570 views

WP REST API core major changes

As of version 4.7 of WordPress the REST API plugin merged into the core. I notice the following major changes: filter[key] = value not working anymore. ?taxonomy = slug not working. Works only by id. ...
2
votes
1answer
11k views

Get more than 10 posts in a specific category with the wordpress api

I'm currently building an Ionic app that uses the Wordpress api. I can retrieve posts in a specific category by using the following: // Retrieve filtered data for the categories to show posts. ...
1
vote
2answers
4k views

Can I authenticate with both WooCommerce consumer key and JWT?

I want to authenticate against both: the WooCommerce consumer key, for system queries and JSON Web Tokens (JWT), for user queries I have installed JWT Authentication for WP REST API. But after ...
1
vote
1answer
2k views

“rest_no_route” - Debug error

I am using Wordpress 4.9.5 and I want to create a custom endpoint like the following: <?php add_action('rest_api_init', 'miningRigsRoutes'); function miningRigsRoutes() { register_rest_route(...
0
votes
2answers
1k views

Update user meta via REST API?

I have a native app project that gets all data from /wp-json/wp/v2. I've registered phone using this register_meta('user', 'phone', array( "type" => "string", "show_in_rest" => true ));...
0
votes
1answer
3k views

Create a new user using WP REST API and declare meta object

I'm struggling here with a question. I'm sending a POST to http://localhost/wp-json/v2/wp/users/ with this JSON data: { "username" : "johndoe", "email": "jondoe@gmail.com", "password": "...
0
votes
1answer
290 views

Extend Woocommerce rest api routes fails

While I'm trying to extend Woocommerce Rest-API routes with a custom one I face the following problem. I have the following class which tries to hook inside Woocommerce API class API_LOADER { ...
0
votes
1answer
1k views

Attach featured image to custom endpoints

I went through this article and create a custom endpoint so that I can specify multiple meta key and value pairs for filtering. However I have no clue to attach featured image on this result. How can ...
0
votes
1answer
331 views

Plugin Sidebar is not Saving Meta Attribute to Post/Page after “Update”

I have modified the tutorial at https://wordpress.org/gutenberg/handbook/designers-developers/developers/tutorials/plugin-sidebar-0/ to meet ES6+ but I am having trouble getting it to actually save to ...
5
votes
2answers
9k 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 ...
4
votes
1answer
5k views

Retrieve all users from wordpress database via REST/JSON API

I've read that the WP REST API v2 retrieves only users that have made a post for the blog. I'm developing an iOS and Android app that needs to use the Wordpress registration. How I could retrieve a ...
4
votes
2answers
5k 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 ...
3
votes
2answers
3k views

Increase per_page limit in REST API

WP 4.8.2 We need to increase the per_page limit on responses to a REST API request. afaik – the limit is 100 There used to be a way to filter that parameter, but it seems this filter hook is no ...
2
votes
1answer
569 views

How do I correctly setup an AJAX nonce for WordPress REST API?

Following a link comment here which led me to these docs, I've tried to set up a nonce for user authentication. I added: wp_localize_script( 'wp-api', 'wpApiSettings', array( 'root' => ...
2
votes
1answer
3k views

Rest API Hook When Post Is Requested

I am aware that I can use the endpoint /wp-json/wp/v2/posts/{id} to fetch a post. I am building an implementation of WordPress that relies completely on the JSON API and its endpoints. It is an ...
1
vote
1answer
190 views

Wordpress: How to create custom REST API route?

How can we create custom REST API route for sending specific data format to Android or IOS app ?
1
vote
1answer
4k views

WP REST API: check if user is logged in

The idea is to show or hide some sections of the site in a theme that's fetching all data from the REST API, using AngularJS. I thought this check would help me (nonce is passed as header, as ...
1
vote
1answer
3k views

Handling nonce generation in AJAX registration process

I am currently working on a multi-steps registration system, based on the new Wordpress Rest API and I got an issue related to the nonce generation and verifying. My first step is to ask the user ...
1
vote
2answers
2k views

WP REST API - Multisite - get posts from all sites

Is it possible / how can I get all posts from all sites on a multisite installation using the REST API? On the front page of the primary site, I want to display recent posts from all the sites; e.g., ...
0
votes
1answer
34 views

Ajax call to my Wordpress website from an external application [duplicate]

I have on website on wordpress and a external web app. I try to make an AJAX call from this external web app to get some info from my wordpress site/ database but i got an error message 400. Here is ...
0
votes
1answer
31 views

Get custom post type REST API not working

I want to load the content of a modal using the REST API of wordpress. I've added the show_in_rest param to the custom post type I've registered in my function file, but I'm unable to load it, I will ...
0
votes
0answers
37 views

AJAX request from Chrome Extension to Wordpress Website

I developed a chrome extension which extract some data from the user visiting page and I want to transmit them to my database by an AJAX call (my website is a basic wordpress website). The point is ...
0
votes
3answers
14k views

WP REST API - Retrieve content from page

I already get posts from categories with: http://domain.com/wp-json/wp/v2/posts?filter[category_name]=category-name but how can i retrieve content from page? - [page_name]=page-name for example but ...
0
votes
1answer
254 views

Does jQuery/Ajax send cookies when using the rest API or do I need to somehow add them?

I've run into an odd situation with user capabilities. I have set up a rest endpoint on my local computer and am the super admin. The rest endpoint is called and the first thing it does is see if ...
0
votes
1answer
46 views

Multisite functions to communicate with individual site functions

I have a multisite plugin that operates at the network level. It's job is to assign additional roles to different sites across the network. For example, I have three sites. Library Course (LMS) CRM ...