Questions tagged [rest-api]

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

Filter by
Sorted by
Tagged with
6
votes
1answer
2k views

Update CPT meta data using REST API

I'm trying to update a CPT post's metadata using the REST API. I can update a numeric metadata element using a POST such as this: example.com/wp-json/wp/v2/posts/73/meta/229?value=2 This method is ...
6
votes
1answer
1k views

WP REST API create post authentication issue

I am getting a 401 or 403 error when trying to create a post from front end. I am using angular in the front end and I want to use basic authorization. I have enqueued the api and created the nonce: ...
6
votes
1answer
1k views

Edit srcset and sizes attributes in Gutenberg image, cover and gallery - blocks

I am looking for a way to adress the responsive srcset and sizes attributes on Gutenberg image blocks - like image, cover and gallery. Usually one would do this with the '...
6
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 ...
6
votes
0answers
1k views

Slow REST API calls on self-hosted WordPress [closed]

I'm using WordPress REST API to access some posts from an app we're creating, but the API calls are really slow! If I'm using the domain in the call like this: https://public-api.wordpress.com/rest/...
5
votes
2answers
14k 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/#...
5
votes
3answers
4k 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 ...
5
votes
2answers
2k views

To Disable Wordpress Rest API or Not To Disable?

I have my blog self hosted running WordPress and I Do NOT need the Wp-Rest API. But as it turns out disabling it is causing to Contact Form 7 To not work. Contact form 7 simply shows the spinning ...
5
votes
2answers
19k 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 ...
5
votes
1answer
2k views

wp rest api v2 return json_no_route

i am using WP rest API v1 and everything is ok. But now i want taste some WP rest API v2. the problem is, when i cal: mysite.com/wp-json/wp/v2/posts or: mysite.com/wp-json/wp/v2/post or ...
5
votes
1answer
6k 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 ...
5
votes
1answer
1k views

When adding a custom REST endpoint, where do you put the endpoint function, and where do you put the function registration call?

WordPress documentation, bloggers, and StackExchange answerers have done a great job of describing the code you write to make a custom REST endpoint, but I cannot find any documentation that describes ...
5
votes
1answer
4k views

Retrieving pages with multiple tags using REST API

I'm having some difficulty understanding syntax to make a call from my application to the wordpress REST API when it it comes to getting pages that contain multiple tags. I have no problem with doing ...
5
votes
1answer
572 views

Including Wordpress in RESTful API

I'm using a great little open-source product called Restler to provide a RESTful API to a Wordpress application. In order for this to work I want to be able to load the Wordpress environment within a ...
5
votes
1answer
2k 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 (...
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
845 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
2k 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
835 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
4answers
4k 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?
4
votes
2answers
2k views

REST API endpoint for elasticpress autosuggest

The AJAX, which is part of Elasticpress, looks like this $.ajax( { url: epas.endpointUrl, type: 'GET', dataType: 'json', crossDomain: true, data: JSON.stringify( query ) } ); ...
4
votes
2answers
9k 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
1answer
5k 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
1answer
3k views

WordPress REST API validation

I'd like to validate the data sent to my end point. https://www.shawnhooper.ca/2017/02/15/wp-rest-secrets-found-reading-core-code/ This post referenced the undocumented validation options. I have got ...
4
votes
2answers
8k 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
14k 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 ...
4
votes
2answers
2k views

how to authenticate for the REST API from a plugin and from command line

I want to try the new REST API but I'm not used to this kind of things. Basically, I want to use it to GET custom posts via ajax and show on the website frontend (I'm building an ajax product ...
4
votes
3answers
6k 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
12k 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
2k 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
1k 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
5k views

How do I use the WP REST API plugin and the OAuth Server plugin to allow for registration and login?

Are there any example projects that do the same? I want to be able to login and register for accounts on my site via the API.
4
votes
2answers
1k 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
3answers
3k 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 ...
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
2answers
4k views

How to call a REST endpoint when a post is published?

I need to make WordPress call a specific REST endpoint when a new post is published, passing the most important post data via JSON. I found a plugin, HookPress, that apparently did just that by ...
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
1k 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
3k 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
2answers
3k views

Modify WordPress Rest Api Request/Response

I am building an application using WordPress Rest API. I want to make simple calls to the API, such as just /wp-json/wp/v2/posts and let the backend have a systematic way how to handle this and serve ...
4
votes
1answer
2k 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
1answer
4k views

How to loop through JSON data in wordpress WP REST API

I am using the WP REST API plugin in wordpress and want to loop through my json data using a for each loop, however when I var_dump the variable that the json data is stored in it gives me an error. "...
4
votes
1answer
786 views

Updating Post Meta with Backbone and the REST API

I'm getting started with a project that is making use of Backbone and the WP REST API, but I"m having a little trouble. Using the built in API JS for models and collections allows me to pretty easily ...
4
votes
1answer
369 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
604 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
670 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
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 ...

1
2
3 4 5
21