Contents
On this page

Create Category - Plugixa Testimonial

POST /plugixatestimonial/v1/categories

Create a category.

Any signed-in user with the plugixa_testimonial_edit capability or WordPress’s edit_posts (Contributors and up, by default).

Request

POST https://your-site.example/wp-json/plugixatestimonial/v1/categories

Request body

Content type: application/json

Field Type Required Description
name string Yes Plain text, must not be blank.
slug string No Made from the name when empty. Made unique by appending -1, -2, …
description string No Plain text.
display_order integer No Defaults to 0.
status string No publish (the default), draft or trash. Any other value is saved as publish.
language_code string No With WPML or Polylang active: the language. Defaults to the default language.
translation_of integer No With WPML or Polylang active: the id of a category this one translates.

Only the new id comes back: read the category with Get Category if you need it.

{
  "name": "Agencies",
  "description": "Feedback from agency clients.",
  "display_order": 0,
  "status": "publish"
}

Responses

200 OK. data.id is the new category.

{
  "success": true,
  "message": "Category created successfully",
  "data": {
    "id": 3
  }
}
Field Type Meaning
data.id integer The new category’s id
message string A human-readable confirmation, translated to the site language

Errors

Status Code When
400 rest_error “Validation failed”. data.errors names the field: name.
400 rest_missing_callback_param name is missing.
500 rest_error The database refused the insert.

Plus the errors every endpoint can return.

Examples

curl -s -X POST "https://your-site.example/wp-json/plugixatestimonial/v1/categories" \
  -u "admin:$WP_APP_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{"name":"Agencies","description":"Feedback from agency clients.","display_order":0,"status":"publish"}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixatestimonial/v1/categories');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_USERPWD        => 'admin:' . getenv('WP_APP_PASSWORD'),
    CURLOPT_HTTPHEADER     => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS     => json_encode([
        'name'          => 'Agencies',
        'description'   => 'Feedback from agency clients.',
        'display_order' => 0,
        'status'        => 'publish',
    ]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixatestimonial/v1/categories', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic ' + btoa(`admin:${process.env.WP_APP_PASSWORD}`),
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ name: 'Agencies', description: 'Feedback from agency clients.', display_order: 0, status: 'publish' }),
});
const { data } = await response.json();

Quick Links

Share