Questions tagged [rest-api]

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

498 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
5
votes
0answers
1k views

Search WP API using the post title

I'm using the WP REST API v2 to try and search for all posts with the same title, what I'm trying to do is create a sort of head-to-head/previous meetings page for 2 teams. At the moment i can ...
5
votes
1answer
1k 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/...
5
votes
1answer
782 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 ...
5
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 ...
5
votes
1answer
810 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
1answer
290 views

How to authenticate custom API endpoint in WooCommerce

I have created custom API, which is working fine, but I am not able to authenticate it, it returns result without checking for keys I have created consumer key and secret key from admin. How to ...
4
votes
0answers
2k views

Understanding SHORTINIT with Wordpress 5

What I am trying to achieve I am looking at using Wordpress decoupled, and most tutorials and guides go into detail on using the Rest API. Recently, I discovered the SHORTINIT option to load a very ...
4
votes
0answers
584 views

WordPress REST API call generates nonce twice on every call

I'm trying to login a user via the REST API, and then retrieve the current user on subsequent requests. As per the documentation, in my plugin, I am creating and retrieving a nonce after a successful ...
4
votes
0answers
3k views

WordPress REST Upload Media

How to Upload Media via the WP REST API ? I am trying to upload media to http://example.com/wp-json/wp/v2/media using POSTMAN. I tried uploading image using the following headers Content-Type: ...
4
votes
1answer
2k 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
0answers
201 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
587 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 ...
3
votes
0answers
26 views

WordPress Rest API only returns content when posttype has editor capability

I am trying to request my post via the WordPress V2 Rest API in the backend. For whatever reason the post content is only returned when my custom post type has the editor support enabled. Is there a ...
3
votes
0answers
2k views

x-wp-nonce is not allowed by Access-Control-Allow-Headers in preflight response

I would like my dev server on http://localhost:8080 to work with my wordpress install's rest api, of which the api base url is at http://localhost/wptest2/index.php/wp-json/ I am currently getting the ...
3
votes
0answers
410 views

Wordpress REST API “rest_authentication_errors” doesn't work external queries?

Wordpress REST API "rest_authentication_errors" doesn't work external queries? I was using following experimental codes for experimental purposes. add_filter('rest_authentication_errors', 'auth'); ...
3
votes
2answers
3k views

404/500 error on /wp-json

I get 500 error on wp-json. if I try to echo get_rest_url() I get example.com/wp-json, which then gives me error 500. I added RewriteCond %{REQUEST_URI} !^/wp-json to my .htaccess, which gave me 404 ...
3
votes
0answers
130 views

How should an old API version be deprecated gracefully?

When researching and reading about the WP REST API utilization I've seen many topics mentioned about how another version should be rolled out but nothing in the documentation regarding a return for a ...
3
votes
0answers
2k views

How to get around WP REST API per page limit without pagination?

So I know that using /wp-json/wp/v2/customposts/?per_page=100&page=2 will allow me to bypass the default of 10 returned at a time. But I am trying to return over 2k custom posts. The only other ...
3
votes
1answer
1k views

Android authentication

I'm using WordPress REST API (Version 2), and I want to authenticate Android native app with my self-hosted WordPress site. How can I perform that using username and password ?
3
votes
0answers
172 views

WP REST API route request explain

Maybe can someone explain or show additional info about "WP REST API route request" from beginning to the end. Main questions, how handle this request in most earlier stage. For example for ajax ...
3
votes
0answers
268 views

Implementing the wp json-rest api

I have a client that wants to use the wp json-rest api to allow third-party sites to push custom posts (in this case property listings) up to our site. I've been looking at using the wp json-rest api,...
2
votes
0answers
76 views

CORS & Remote access to WP via RestAPI

I have built an app which enables the manager of many WP sites to make RestAPI GET, POST, PUT & DELETE requests which work perfectly when using them from this Apps, when the WP site are hosted on ...
2
votes
0answers
45 views

How to filter Post using Meta Data REST API

I want to list post that filtered by Meta Data I have tried many solutions i found here but i can't make it work. The last solution i tried is to add this to my functions.php add_filter( '...
2
votes
0answers
72 views

Limit REST API output to current logged in user that is also author of the content

https://developer.wordpress.org/rest-api/using-the-rest-api/frequently-asked-questions/#require-authentication-for-all-requests This requires authentication for all reque​sts. add_filter( '...
2
votes
0answers
226 views

Solve cors problem using rest api or ajax

I'm building an app with nuxt using WP as a CMS, so I have this code in my functions.php to allow any origin (temporary) using the rest api and admin-ajax urls function add_cors_http_header(){ // ...
2
votes
0answers
161 views

Wordpress API returns empty page when page is less than X-WP-TotalPages

I am querying in the Wordpress API for all pages of media attachments. I am going page by page. I have about 5800 pages and when I hit pages 50-53 they return a blank or more of a [] but it is a ...
2
votes
0answers
163 views

How to insert Comment metadata via REST API

I am trying to insert comment from my android app , i am using REST API and POST method /wp-json/wp/v2/comments/ The method is working great , but I would like to include metadata when inserting ...
2
votes
0answers
156 views

Create Session with JWT

I'm currently working on a shop like project that uses React as frontend and Wordpress with Woocommerce as a backend. To authenticate with the API I use the JWT Authentication for WP REST API, which ...
2
votes
0answers
314 views

Get templated page/post content via the WordPress API

I've been tasked with converting a WordPress site into a single page application so a persistent audio player can be added, while retaining its current theme. I need to do this in such a way that the ...
2
votes
0answers
434 views

Not all featured image sizes available in Rest API

I'm using Vue.js to consume the Rest API for both posts and a custom post type. I'm using the _embed query on the URL for the endpoint to get sizes for the each featured image. The issue that I'm ...
2
votes
0answers
63 views

Extending wp JavaScript base class to make a post request to a custom REST endpoint

I've defined a REST endpoint /my-plugin/v1/post-read to show whether a post has been read or not, per-user. In PHP, my plugin keeps track of this depending on page views while logged in. I'm now ...
2
votes
1answer
215 views

ACF attachment custom field in rest response

I created an extra select option ACF field for media uploader and I would like to retrieve the associated values in Gutenberg MediaUploader onSelect. Is there a workaround for this case?
2
votes
0answers
1k views

Get all post media images via WP REST API

We want to build a back-end for a mobile app using WordPress. We are trying to get all post images, but when we call https://api.com/wp-json/wp/v2/media?parent=58 we are getting only the first image ...
2
votes
1answer
435 views

Flush Rewrite Rules on init or rest_api_init?

if I'm using the REST API to create endpoints in my plugin, should I be flushing rewrite rules on init or in rest_api_init? I realize that it should be done on plugin activation/deactivation. However,...
2
votes
0answers
98 views

Rest API and Custom Fields

how can I create a new post post (custom type, with custom fields) on the front end using rest api and an http request? Is this even currently possible to create a new post with custom fields through ...
2
votes
0answers
1k views

WP Rest API max limit include parameter?

I'm using the rest API to get only selected posts though Rest API. I have used include=<ids> parameter. I have send the API request like: http://example.com/wp-json/wp/v2/posts?include=11,12 ...
2
votes
0answers
564 views

Full page NGINX (or Cloudflare) caching and WordPress nonces

Goal: I want to cache the full WordPress response via NGINX and exclusively use the REST API for the user specific parts. Issue: I can't get an authenticated nonce to use against the API. My plan ...
2
votes
0answers
734 views

create new post using rest API and set featured Image from an external link

I am new to Wordpress. I need to create a new post from the Rest API which has its featured image from an external link. I can successfully create a new post using the rest API plugin, how do I add ...
2
votes
0answers
1k views

Is it possible to update a post meta field through REST API if the format of it when registered is nested?

I am able to get the custom REST API fields using meta key values to be formatted like this: "location": { "lat": "000001", "long": "000002" }, The works fine when I am trying to retrieve ...
2
votes
0answers
273 views

Remote REST request to check login status

There are 2 wp installations, A and B. Is it possible to do a remote rest request from site A to find out if an user is logged into site B? If yes, how? With this information adjustments would be ...
2
votes
1answer
408 views

Is it possible to nest the JSON result of Wordpress REST API?

I have been try to search around if it is possible to have a 'nested' JSON response in adding some custom fields through register_rest_field I have this code: function video_get_post_meta($object, $...
2
votes
0answers
77 views

WP REST- video and audio players

Im build VUE JS based theme, and Im using WP REST v2. And there is a problem, I can't make video and audio playlist working (build-in WP feature). I already added: wp_enqueue_style( 'wp-mediaelement' ...
2
votes
1answer
644 views

Permission Check for REST API Endpoint Runs Twice?

I'm making a plugin using the WP REST API, and everything seems to be working as expected. However, there is behavior I don't understand. The authPermissionCheck() method is executed twice for each ...
2
votes
0answers
201 views

How to filter users on custom meta fields in WP JSON v2?

I am trying to filter users on meta field, say abc is user meta field and value is 123 for user1. I have tried filter parameter with WP query like parameters, but it returns all users. 'search' ...
2
votes
1answer
452 views

How can I return an image from a custom REST API endpoint?

I'm brand new to Wordpress development; Trying to return an image from a custom endpoint, but it seems to want to serialize everything to JSON. I did manage to get it to work using echo. Is that a ...
2
votes
0answers
414 views

Prevent wp_insert_user from creating duplicate users

I have a custom plugin that automatically creates a new user via wp_insert_user() if the current user does not exist yet. We use data from our remote ldap server to provide the new user's details (...
2
votes
0answers
139 views

Login WordPress website using wp-rest api

I am using WordPress 4.8 and i am new to rest api . I have 2 websites , one is www.example.com and second is www.example.com/site2. That is second website is installed inside the first . In example....
2
votes
0answers
226 views

WP REST API returns incorrect data?

I'm trying to get a page from the API based on its page template however it seems to be returning incorrect data? so I'm unsure whether I am using the API correctly. http://domain.dev/wp-json/wp/v2/...
2
votes
0answers
1k views

Passing Meta array in wp-rest api

I have been trying to pass a meta array to a post via front-end using WP-REST API but to no avail. functions.php: //Add custom field to REST API function filter_post_json( $data, $post, $context ) { ...

1
2 3 4 5
10