Create page in category using REST API

The REST docs show how to create a page: https://developer.wordpress.org/rest-api/reference/pages/#create-a-page

But it makes no mention of how to set categories for that page. It is also not mentioned in the categories page (https://developer.wordpress.org/rest-api/reference/categories/)

I assume this has to be done by adding data to meta property but I can’t find an example.

How do I create a page in specific categories?

How to deliver webp format of images to WP REST API

I use WP Offload Media Lite plugin to offload upload image to S3. I use raw S3 URL (not CDN) and choose remove file in server option. Then I use EWWW Image Optimizer plugin to convert image on S3 to .webp format. I run bulk optimize and there are .webp copies on S3. Then I choose JS Webp Rewriting to delivery .webp to my site (because I use Nginx) and it works well. But my partner request me deliver .webp to WP Rest api too. Because when he call : http://domain.com/wp-json/wp/v2/posts?_embed&slug=this-is-post-slug (GET) , it returns response that has only .jpeg, not .webp. I’m not familiar with WP rest api. How could I do that?

WordPress doesn’t send a notification email when submitting a comment using REST API

When I submit a comment on the WordPress website, it sends me a notification email.
but when I submit a comment through REST API, WordPress doesn’t send me a notification email.
What should I do to make WordPress send a notification email when I submit a comment with REST API?

WordPress plugin called “YITH WooCommerce Questions and Answers Premium”, Its data is not showing in REST API’s

I am using a plugin to add questions and answers to Woocomerce products, it works fine on webiste but when I try to get data through API those questions and answers are not in cluded in API. And this plugin is not using any post type so we can get data separately. What i can do now?

Are there any instances of any rules for Tabaxi that say they only need 4 hours of rest?

One of my players has just started playing a tabaxi, she is sure she read rules that as a racial trait she only needs 4 hours for a long rest. However neither of us can find rules stating this. She is happy not doing it but I just wanted to confirm have these long rest rules ever stood for tabaxi?

I have referred to DnD beyond and have the official rules for tabaxi in physical form and confirmed for 5e it is 8 hours.

What I am asking is if there is a source she may have read, either from an older version of DnD, or pathfinder or an unofficial rule or UA that was not progeressed at all. She accepts it is possible she either mis read or just imagined reading it somewhere.

Composer Installed Package with WordPress Rest API Endpoint

I am trying to use the Square SDK with a WordPress website. I installed Composer and the Square SDK. I created a WP_Rest_API, but when trying to use the Square classes inside of the .php file, I get an error.

  1. I created a new plugin in my wordpress plugins folder.
  2. In the .php file inside my plugin, I require the "autoload.php" file of Composer from my root directory.
  3. When trying to use the classes from the Square SDK I get an error.

Why?

Thank you!

Custom Post Type and Custom REST API Endpoint result in Gutenberg editor not working

I have a custom post type (article) and have implemented a custom REST API endpoint for that post type. I can retrieve single and multiple articles via the custom endpoint without any issues.

However, when I try to add a new or edit an existing article post within WP Admin, I just get a white screen. The web console shows an error that the rest route does not exist but it is using the standard WP REST Route "No route was found matching the URL and request method." The GET call is to /wp-json/wp/v2/article. The route should be /wp-json/kbs/v1/articles – and that route works. When registering the post type I have the following args…

'show_in_rest'          => true, 'rest_base'             => 'articles', 'rest_controller_class' => 'KBS_Articles_API' 

How can I ensure that WP uses the correct route when loading the block editor? Editing with the classic editor works fine.

Headers already sent error with get_template_part in REST API call

Crosspost from StackOverflow

I’ve looked at multiple other questions about this warning (Headers already sent…etc) and this thorough explanation, but I’m not finding a solution for the circumstances I’m dealing with:

  1. I have a custom WordPress REST API endpoint that returns the output of get_template_part. When I just call get_template_part normally on a page, there’s no warning. It only appears when it runs in register_rest_route‘s callback.
  2. I am also fetching data from an external API using this library. The error started when I started making these requests. I’ve tried making the request both inside and outside the template part, the latter either within register_rest_route‘s callback or as an init action.
  3. The line that triggers the error is an img tag, where I’m echo-ing a URL as the src using data from the external API response. There are other echo calls all over this template, so I doubt that’s the issue.
  4. The line in question actually works fine and does its job. I just need to get rid of the accursed warning.

Code:

Inside functions.php:

<?php    //the api endpoint declaration   add_action( 'rest_api_init', function () {     register_rest_route(         'theme/v2',   // namespace         '/homepage',  // route         array(                  // options             'methods'  => 'GET',             'callback' => 'build_home',         )     );   });    //the callback for the wordpress api   function build_home() {      // this is the external API request, using their PHP library.      // I linked the library above. The request returns an object with a bunch of data     include_once(get_template_directory()."/arena/arena.php");     $  arena = new Arena();     $  page = $  arena->set_page();      $  per = 8;      $  slug = 'concepts-bo-6ajlvpqg';      $  channel = $  arena->get_channel($  slug, array('page' => $  page, 'per' => $  per));      //I'm passing the response from the external API (in $  channel) to get_template part     //get_template_part is then the output for the wordpress API request     get_template_part('custom-home-template',null,array('channel'=>$  channel));  }   ?> 

Inside template part:

<?php   $  channel=$  args["channel"];   ?>    <div id="concepts-box" class="bodycontent reg-width">     <?php foreach ($  channel->contents as $  item) { if($  item->class=="Image"){       $  img=$  item->image["square"]["url"];       ?>     <div class="concept-wrapper">       <!-- the line below is the one that triggers the error -->       <img lozad src="<?=$  img; ?>">     </div>     <?php }} ?>   </div> 

Full warning:

<b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /filepath/wp-content/themes/theme/custom-home-template.php:63) in <b>/filepath/wp-includes/rest-api/class-wp-rest-server.php</b> on line <b>1372</b><br />