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 was to expose a rest endpoint that returns a valid nonce shown below: add_action( ‘rest_api_init’, function () { register_rest_route( … Read more

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 It works as expected. But, What happen If there are 200+ post IDs. The request like: http://example.com/wp-json/wp/v2/posts?include=11,12,…,200 What is the max limit for include parameter? I have used the … Read more

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 a POST request? I cant seem to find a solid either way. I have been developing a … Read more

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 Answer 1 Check out ACF to REST API – https://github.com/airesvsg/acf-to-rest-api You can optionally turn on/off which fields you want to enable. // Enable … Read more

Why my admin doesn’t work after adding rest_prepare_post filter?

When I add a filter to custom get_all_posts API callback, API works, but the admin page for each page is blank. Why? function get_all_posts( $data, $post, $context ) { return [ ‘id’ => $data->data[‘id’], ‘date’ => $data->data[‘date’], ‘date_gmt’ => $data->data[‘date_gmt’], ‘modified’ => $data->data[‘modified’], ‘title’ => $data->data[‘title’][‘rendered’], ‘content’ => $data->data[‘content’][‘rendered’], ‘main_text’ => $data->data[‘main_text’], ‘featured_media_url’ => $data->data[‘jetpack_featured_media_url’], … Read more

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 trying to add a front-end AJAX control to let users manually set a post as “unread” or “read”. I’ve read that … Read more

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 int> For everything else, including my custom endpoints, and custom params/fields added to the api, it works perfectly. But the moment i add the author part, … Read more