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
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( '...
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 ...
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,...
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 ...
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[...
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 ...
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 ...
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
142 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 ...
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 ...
1
vote
1answer
6k 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
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 ...
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 ...
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/...
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 ...
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 ...
4
votes
2answers
16k 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
12k 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 ...
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 '...
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 ...
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 ...
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:...
4
votes
1answer
1k views

Filter posts by multiple custom taxonomy terms using AND operator in REST API v2 (WordPress)

I've created a custom post type called 'events'. I've also created a custom taxonomy called 'event_categories' containing the 12 months of the year. I am trying to get 'events' held in August AND (...
3
votes
1answer
538 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. ...
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(...
1
vote
1answer
28 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....
1
vote
1answer
1k 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 ...
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
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
106 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 { ...
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 ...
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 ...
3
votes
1answer
4k 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 ...
2
votes
1answer
2k 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
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
10k 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
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
1k 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
2answers
735 views

curl POST work with user meta but not the custom user meta

I created a custom user_meta, but I cant update it via curl. I can do this with user_meta curl --header "Authorization: Basic ACCESS_TOKEN" -X POST -d "description=New description" http://domain.com/...
0
votes
3answers
12k 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
127 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 ?
0
votes
1answer
187 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 ...
0
votes
1answer
32 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
42 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 ...
0
votes
2answers
3k views

Rest Api v2 orderby meta_key in custom post type

I get my posts of an cpt like this: http://www.mywebsite.com/wp-json/wp/v2/cpt at this posts there are shown post_meta values. Does anyone know a way to order the posts by the meta like this: http://...
0
votes
1answer
3k views

Get the Category Name instead of ID from WP-API

I'm trying to get the category name instead of the ID from the WP REST API for my Custom Post Type. Some articles about endpoint modification gave me some ideas on how to solve it, but unfortunately i'...
0
votes
1answer
109 views

Developing Themes with React/Angular

I am learning WordPress REST API and ReactJs.I think ReactJS would be a great asset for developing faster themes and plugins.But I have a question.May be I am new to React that's why i am confused ...
0
votes
2answers
3k 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 ...