Questions tagged [rest-api]

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

393 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
1
vote
0answers
34 views

Woocommerce custom endpoints

Currently, I'm an android developer(Java) and trying to add some custom endpoints to my Woocommerce site. I've wasted so much time to understand concepts of WP, but still can't get clear answer. So ...
1
vote
0answers
29 views

Register REST route with a multi-value parameter

I want the UID parameter of this REST route I'm registering to accept both a single value or multiple values (let's say a comma-separated list, like "800,300,100"). Is there some standard way to do ...
1
vote
0answers
33 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(){ // ...
1
vote
0answers
23 views

Update a post based on results from GET request to another server

I need to use GET requests to retrieve the current status of a device and then update the body of a specific Wordpress post with the text data sent by the external device (for reference, it will use ...
1
vote
0answers
38 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 ...
1
vote
0answers
24 views

Woocommerce REST API - updating an order changes custom tax calculations

We have a online woocommerce store that processes two types of orders: shipping and instore pickup. Shipping calculates taxes based on billing address and instore uses the store address (zip). ...
1
vote
0answers
31 views

WP rest api returns 404 only when author param is used

I have a multisite wordpress installation on aws linux, working perfectly fine. The WP Rest api is also working exactly as it should. Except for one single case. /wp-json/wp/v2/posts?author=<some ...
1
vote
0answers
124 views

Blocks Rest API rest_cannot_delete

I'm trying to make a Postman call to the Wordpress API to delete a block. However, I keep getting a 403. This user is used to add and delete pages, tags, and posts just fine using the Application ...
1
vote
1answer
164 views

wp_remote_get() returns 403 while file_get_contents() does not

We are working on a WordPress plugin and we require an API call. We are using the api: http://www.geoplugin.net/json.gp?ip=8.8.8.8 In this context: $response = wp_remote_get("http://www....
1
vote
0answers
204 views

Create post using rest api with html content

I'm trying to create a wordpress post with html code in content for images but I have a problem. For example my content looks like: <p><img src="https://avatars3.githubusercontent.com/u/1?s=...
1
vote
0answers
169 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 ...
1
vote
0answers
21 views

need help with a user-specific custom page template

I created a custom page template that will show sales from a hotel. I have 3 users and I want each user to only see their hotel sales on a user profile specific page. The template calls data using the ...
1
vote
0answers
76 views

How do I add meta when creating a post with rest api?

I have this code that inserts a post into WordPress site using Rest API: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $row->site_url."/wp-json/wp/v2/posts"); curl_setopt($ch, ...
1
vote
1answer
203 views

Get Block Attributes in JSON REST API

I am trying to make my block attributes show up in the REST API. To start, I've added the rest_api_init hook to whitelist my block for inclusion. add_action( 'rest_api_init', function () { ...
1
vote
0answers
26 views

Setting/unsetting terms using the Backbone JavaScript client

I'd like to set and delete terms in my custom taxonomy using the WordPress Backbone JavaScript client, which provides access to the REST API in JavaScript. I can't find an example or suggestion in ...
1
vote
0answers
40 views

How to prepare WordPress Rest data for Preview Changes?

I am currently building a custom theme by using WordPress Rest API, ACF and Vuejs. I am able to delete some data for published pages/posts using rest_prepare_page filter and rest_prepare_post filter....
1
vote
0answers
46 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 ...
1
vote
1answer
50 views

Notify Jenkins of new post on Wordpress

Does anyone know if it is possible to "notify" a Jenkins VI server whenever a new post is made on a headless wordpress installation? The reason why I'm asking this is because I'm using gatsby to ...
1
vote
1answer
143 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?
1
vote
0answers
65 views

How does one perform a sub query with different post types

I am creating an application for a home cleaning service using the WP API. I have two custom post types called property and job. The property posts contain a list of home addresses and phone numbers....
1
vote
0answers
173 views

Custom Post Type not showing in Rest API on Multisite

I'm using WP Multisite and can't seem to pull through my custom post types via the API. <?php function terms_post_type() { $labels = array( 'name' => _x( 'Policies', '...
1
vote
0answers
887 views

How to use current_user_can() in register_rest_route()?

I'm trying to assert current_user_can() in the permission_callback method of a register_rest_route function. However, it always returns false. Upon further debugging, I see that wp_get_current_user() ...
1
vote
0answers
79 views

post meta parameter in post custom-post-type endpoint with restapi

I'm trying to create a new custom post via the native Wordpress REST API POST /wp-json/wp/v2/CUSTOMPOST at the moment I used the wp-rest-api-controller plugin to activate the endpoints the custom ...
1
vote
0answers
30 views

Ability to make API calls out of Wordpress as well as executing SQL?

I'm pretty new to Wordpress, so I'm risking some downvotes here... but, I'm curious, are there any recommended plug-ins that have the ability to make REST API calls? I have access to a third party ...
1
vote
1answer
94 views

Access Wordpress data from external PHP application.

I am a volunteer in a non-profit organization. I have taken over maintenance of a number of apps written in PHP/SQL/Dreamweaver. The apps are over 10 years old. I am migrating these apps from PHP/SQL ...
1
vote
0answers
565 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 ...
1
vote
1answer
394 views

WordPress Rest API Create Post

Is it possible to login to my different WP website from another WP website (they have different domain and host) ? Actually, I am trying to create a post on one of my site from my another site using ...
1
vote
0answers
52 views

What is the way to share data between sites in a multisite

We want to display the same data on multiple sites in a multisite. This data needs to be added/edited by the client. We can create a custom post type and use the switch_to_blog function to get the ...
1
vote
0answers
107 views

Wordpress + REST API v2 and private pages Load by slug

Im creating WP theme based on VUE, anyway I load pages based on slug - no by ID. I use base X-WP-Nonce header authentication, it working well with revision etc. So now I have a private page and my ...
1
vote
0answers
72 views

Select posts by name and category per REST API

I have a site with a form, the form has 3 inputs. One takes a number, another a date, and another a select option. I made posts with categories from this select. How could I search on click of the ...
1
vote
0answers
126 views

WP REST API can't set post tags

I create post with WP REST API but can't set tags for the post. var post_data = { 'author': 1, 'title': 'My title', 'content': 'My content', 'status': 'publish', 'tags': ['tags1','...
1
vote
0answers
47 views

Why is multisite rest API keep giving me results for root site only?

I have a multisite wp installation and am trying to access the posts from the rest api for a subsite. I keep getting the results for the root site instead of the subsite. I'm using Postman to test the ...
1
vote
0answers
128 views

Exclude objects from Wordpress API based from ACF field using rest_prepare_{$post_type}

Lets say i only want custom posts where (date('Y-m-d H:i:s')<{acf_date_field}) I tried to return null; from my_rest_prepare_post. It seems like its working, but is this good practice, or should i ...
1
vote
1answer
715 views

filter custom post in rest api with custom function

i have 3 custom post type : artists, songs, videos songs and videos have a meta that sort artist id of songs or videos filter in rest api couldn't return filtered post by artist id custom meta so i ...
1
vote
0answers
94 views

Checks when fetching data from multiple REST API endpoints in Gutenberg

I'm developing a plugin for the new Gutenberg editor and I need to retrieve data from two REST API endpoints: registerBlockType( 'my/block', { title: __( 'My Block' ), icon: 'email', ...
1
vote
0answers
398 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 ...
1
vote
0answers
182 views

Limit post creation by role

Hi I want to limit post count a role can create. I am currently using Bainternet Posts Creation Limits. It works from dashboard but not for rest api.
1
vote
1answer
2k views

featured image not found in json from wp rest api

I found that the image must be in the element featured media but I found another link that leads to another link contains this message in French means ( Sorry, you do not have permission to do that.) ...
1
vote
1answer
38 views

How to load content from many posts on a page, only if needed

I have a page with a list of links to a custom post type (using wp_query and the_permalink()) When a link is clicked, some custom fields from that post should appear in a lightbox. I can load the ...
1
vote
0answers
292 views

Data storage for JS app using WP REST API

Just wanted to get some other opinions on what everyone thinks might be the most efficient ways of accomplishing the following. So I have been working on a react-based app that takes advantage of ...
1
vote
0answers
131 views

wp_remote_get times out on api request but jquery GET and postman work?

I'm working on a project with two themes. Theme 1 contains a custom WP REST endpoint I made. Theme 2 needs to make a GET request to the endpoint. Both projects are hosted locally. When I make a ...
1
vote
0answers
310 views

Copying media from multisite subsites to main website

I have a multisite install -- set for using subdomains and mapped domains -- with websites from several clients on it and I would like to create a copy of each and any uploaded media file of my ...
1
vote
0answers
62 views

upload_files cap to not loggen in users - add_cap to not logged in users

When not logged in users upload files to the media endpoint, the return message is: "Sorry, you are not allowed to create posts as this user." I would like to allow not logged in users to be able to ...
1
vote
2answers
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 ...
1
vote
0answers
329 views

Curl requests sent two times

i've an issue with my curl request and i think it's coming from wordpress, i'm using wordpress to push data using curl & an API here is an example of curl method : public function pushtest() { ...
1
vote
0answers
401 views

Secure REST with nonce works only when not logged

I am extending the WordPress REST api, registering a route, and pretends to make it secure. The endpoint should be acessible only by logged users, but I didn't found something specific for that in ...
1
vote
1answer
167 views

Add Data to Response of WP-JSON Root

The default content at /wp-json/ contains name, description, url etc. but I want to add some additional content at this root level. I see lots of ways to modify the responses of items with object ...
1
vote
0answers
322 views

Rest api return all users (even without content) to all users

I'm using the REST API to return a list of all users (using Vue) on an Intranet site. I'm using this code to allow the API to return them: add_filter( 'rest_user_query', 'custom_rest_user_query' ); ...
1
vote
1answer
343 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 ...
1
vote
0answers
437 views

Create multiple posts with WP REST API at once

I managed it to create single posts with a simple JSON object via the WP REST API like... { title: "My Title", content: "My Content", excerpt: "My Excerpt" } I'm wondering, if there is a way ...