Questions tagged [rest-api]

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

Filter by
Sorted by
Tagged with
4
votes
2answers
11k 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
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 ...
4
votes
3answers
3k views

WP REST API only returning partial list of users

Started working with the WP REST API for the first time. Our ultimate goal is to dynamically load UI elements based on which user is presently logged in. However, my attempts to pull a list of all ...
4
votes
1answer
4k views

Wordpress REST Create Post of Custom Type

I am using the REST API to create posts. I am able to create normal posts, but I would like to create posts of custom type. http://example.com/wp-json/wp/v2/posts I am trying to POST to the above ...
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
2answers
9k views

Get Image URL instead of Attachment Id in Rest API

I want to show recent posts in my Android application and I'm suing this end point to get the list of posts https://www.geekdashboard.com/wp-json/wp/v2/posts How can I get the complete URL of ...
4
votes
3answers
4k views

Why is per_page not working with categories in WP API?

To start I've been searching through several questions and documentation pieces but it seems with WordPress' v2 many of the old questions are no longer valid. What I am trying to do is get all posts ...
4
votes
2answers
1k views

Filter out results from REST API

I want to build a plugin to remove all posts by specific users from rest json output. How can I add a filter or hook to do that?
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
1answer
874 views

REST API: How can I restrict a custom post type to only be accessible by authenticated users?

I have a custom post type configured to be accessible via the WP Rest API v2. How do I lock the access to this custom post type so that only the authenticated users can perform GET requests?
4
votes
2answers
981 views

How to feed a HTML5's EventSource with a REST API custom endpoint?

So in this quest to build a custom pseudo web chat service with Telegram, I'm trying to get the messages Telegram sends to the server and redirect them to frontend. SSE with HTML5 EventSource seems ...
4
votes
2answers
3k views

How do I Filter Custom Post Type by Custom Taxonomy in the newest Wordpress RESTful API?

I've a Custom Post Type called clock and a taxonomy called clock_category on my website. It is working well and All the clocks can be accessed from the REST endpoint https://myapp.dev/wp-json/wp/v2/...
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
1answer
686 views

Get the list of enqueued/registered scripts for a specific post?

I am exploring how to build a theme where most of the pages are loaded using the Rest API. I can load the index page and from there make GET requests to get posts json data and after build its content ...
4
votes
3answers
2k views

Gutenberg custom block plugin with custom image sizes

I am using a custum gutenberg block plugin for wordpress(https://neliosoftware.com/blog/how-to-create-your-first-block-for-gutenberg/) This block is using an image but always choosing the full size ...
4
votes
1answer
1k views

Disable external access to REST API Endpoint

I'm playing around with the WP REST API and have setup a route that is used to create a new user when a form is submitted from the homepage. Here is how I setup the endpoint: add_action('init', '...
4
votes
0answers
828 views

WP REST API returns blank response if post is too long

I'm working on an iOS app that requires the use of WP Rest API to fetch posts. Everything is working smoothly and I fetch posts by ID using this endpoint: https://example.com/wp-json/wp/v2/posts/...
4
votes
1answer
531 views

Basic auth WordPress REST API dilemma

Today I tested Basic Auth for the WordPress REST API and it worked perfectly. However, I heard this was a dangerous way of authentication. This is understandable, since people can look into JS files ...
4
votes
1answer
1k views

Creating a post with the REST API, curl and oauth returning 401 error

I'm trying to create a WordPress post using the REST API, OAuth, and cURL. However, I'm running into some trouble. I'm able to create a blank post (no title, slug, etc) using the following code: $...
4
votes
0answers
4k views

WP REST API V2 - Retrieve sub page by full slug (URL/Path)

I'm struggling to see if this is natively supported, or if it's not the best place to implement this functionality - in my app (Laravel) or the same side as the API (WordPress). Retrieving a single ...
4
votes
1answer
553 views

Detect page type by url (Archive, single, page, author,…)

Update:Really short version How do I get $wp_query for a given url which can be anything (single, page archive, custom post type, author, year, month,...)? TL;DR I need a function which can return ...
4
votes
0answers
172 views

Retrieve CSS and JS From the REST API

Does anyone know of a way to get a list of all registered styles and js scripts in-use on a site via the REST API? Essentially was wp_print_styles() does?
4
votes
1answer
505 views

Using the REST API (v2) javascript client on a private namespaced route

I am using the latest version of the REST API plugin in a project and I've added my routes to a separate namespace (as recommended in the documentation). The javascript client included with the API ...
4
votes
0answers
1k views

How to allow users login to WP from external domain and make REST requests

Basically what i want to do is: Use Wordpress as a login system and data storage for web-application on another domain. Make users able to register and perform REST calls from the application. Let ...
3
votes
4answers
3k views

REST API, get user role?

I'm trying to figure out how to retrieve a user's roles from the API, but I haven't been able to sort it. Is this information not accessible by default? Can anyone point me in the right direction?
3
votes
2answers
3k views

Verify nonce in REST API?

I would like to understand the best practices regarding nonce validation in REST APIs. I see a lot of people talking about wp_rest nonce for REST requests. But upon looking on WordPress core code, I ...
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 ...
3
votes
1answer
10k views

WP Rest API v2 return posts with specific tag

I am trying to get posts from blog: http://christianconcepts.com/ which are tagged "appcontent". I tried this querry: http://christianconcepts.com/wp-json/wp/v2/posts/?filter[tag]=appcontent but ...
3
votes
1answer
12k views

WP Rest API v2 filter and display latest post with specific tag

I need to display the latest post with a specific tag. Example: User tags a post 'featured', but forgets to untag earlier posts. So I want to ensure that the latest post tagged 'featured' is what ...
3
votes
1answer
595 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. ...
3
votes
1answer
2k views

WordPress 4.7 REST API endpoints

So with WordPress 4.7 the REST API endpoints will be merged into the core which I'm really looking forward to. On setting up a test site with the 4.7 beta 4 installed, I wasn't able to find the ...
3
votes
3answers
601 views

How to check WordPress website username and password is correct

On my site i have one form for client to submit their WordPress site details. On that form containing these fields WordPress admin url, username, and password. I want to check their login details are ...
3
votes
3answers
17k views

wp-json/ return 404, but wp-json/wp/v2/ works fine on my nginx server

When I access my WordPress site as www.example.com/wp-json/ I got this 404 error. `{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}` ...
3
votes
1answer
3k views

Does the REST API (official) support custom post types?

Having browsed the official WordPress REST API site - and looking at the various endpoints - I cannot find information of custom post types. I appreciate there is the WordPress REST API Plugin that ...
3
votes
1answer
7k views

How to filter by category in REST API, excluding posts also in other category term?

I'm using REST API to load a several posts from other site, each post must belong to a different category. However I have one "Featured events" category, that includes posts also shown in other ...
3
votes
1answer
1k views

WP MultiSite API - Create new sites

I'm building an app for iOS/Windows. I want to allow my users to register / create a new sub site on my domain via the app. How can I achieve this? Does the REST API allow this? Thanks.
3
votes
1answer
421 views

Does pre_get_posts affect REST API responses?

I'm trying to limit the content that is returned via REST API routes to only contain content published by the current logged in user. I'm trying to do this using pre_get_posts which works fine when in ...
3
votes
1answer
3k views

Does the Wordpress API work with multisite?

I’ve found next to no information on whether the rest API works with Wordpress multisite setup. Does it?
3
votes
1answer
994 views

How to: Rest endpoint returning empty object

I'd like to implement a custom REST endpoint that can also return an empty object. However, in the case where it should return an empty object, the empty associative array returned by the callback is ...
3
votes
2answers
4k 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

WP API : date_query parameter

I'm using Wordpress API just to perform some tests. I'm currently working with the date_query parameter, which, in my case, doesn't work as expected. Just consider this request : https://wptest....
3
votes
1answer
1k views

Retrieve custom fields on Categories, using WP-API

I've added a single Advanced Custom Field to the categories taxonomy (that appears to work as expected) and am trying to retrieve it along with the categories using the REST API, via /wp-json/wp/v2/...
3
votes
1answer
3k views

How to filter or search the posts using postmeta tables custom meta fields with wordpress REST API

I'm new to wordpress and also working with WP REST API for mobile application development for the wordpress website. Here I want get data's filter & search based post meta custom fields. I've ...
3
votes
1answer
3k views

Rewrite /?rest_route=/ link to /wp-json/ without changing default permalink structure in apache

How to rewrite url of wordpress rest api from http://example.com/?rest_route=/wp/v2/ to http://example.com/wp-json/wp/v2/ without changing (default) permalink structure? Need this for apache (htaccess)...
3
votes
1answer
104 views

How to make an meta_query optional?

I added this snippet of code to my functions.php to be able to make a request to a custom post type and filter by book_id add_filter( 'rest_gallery_query', function( $args ) { $args['meta_query'] = ...
3
votes
2answers
824 views

Wordpress pods io - Rest API for fetching fields information for custom post type

Hi I have created a custom post type using pods io. Whenever I hit the rest API for a custom post type, I get data for all the posts created using that post type. But what I need from rest API is the ...
3
votes
1answer
1k views

Gutenberg - how to correctly perform ajax request on backend

I have simple block with server-side rendering on frontend. PHP: register_block_type( 'some/block', array( 'render_callback' => 'render_my_block', 'attributes' => array( '...
3
votes
3answers
2k views

WooCommerce: Can't use wc_get_products for custom REST API endpoints

I'm trying to create some custom REST API endpoints which get products with some special conditions, for example, one endpoint for featured products. I tried to use the wc_get_products function like ...
3
votes
3answers
917 views

Show custom post type endpoint in REST API just if user has capability

I created a custom post type for WP, that should just be visitable for user that have a custom capability read_cpt. Within templates and pre_get_posts I can run checks to include or exclude the CPT by ...
3
votes
1answer
3k views

register_rest_field for custom taxonomy fields that are assosiated with custom post type

I am trying to register a rest field for my custom taxonomy's custom meta fields. I followed the tutorial at Modifying Responses . The code worked great for adding a rest field for post meta data for ...

1
2
3 4 5
17