Contents
On this page

Create Testimonial - Plugixa Testimonial

POST /plugixatestimonial/v1/testimonials

Create a testimonial, with its categories and custom field values.

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

Note. When Auto-approve is on in the settings, a pending testimonial is saved as approved. When admin notifications are on, a create sends the same “new testimonial” e-mail a visitor submission does.

Request

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

Request body

Content type: application/json

Field Type Required Description
client_name string Yes Who gave the testimonial. Plain text, must not be blank.
testimonial_text string Yes The testimonial. HTML allowed in a WordPress post is kept. At least 10 characters once tags are removed.
rating integer No 1 to 5. Defaults to 5.
client_role string|null No Job title. Plain text.
client_company string|null No Company. Plain text.
client_photo_id integer|null No A Media Library attachment id. null or 0 for none.
website_url string|null No A link shown with the testimonial.
video_url string|null No A YouTube or Vimeo link, or the URL of an .mp4, .webm or .ogg file. See Video testimonials.
status string No pending (the default), approved, rejected or draft.
is_featured boolean No Defaults to false.
display_order integer No Position in the global manual order. Defaults to 0.
source string No Free text. The column defaults to manual.
categories integer[] No Category ids. Ids that do not exist are stored but never shown.
custom_fields object No Values keyed by custom field key. Plain text. An empty string removes a value. Keys are not checked against the custom field definitions.
language_code string No With WPML or Polylang active: the language. Defaults to the current, then the default language.
translation_of integer No With WPML or Polylang active: the id of a testimonial this one translates. It joins that one’s translation group.

The answer carries only the new id: read it back with Get Testimonial if you need the record. created_at and created_by are set for you.

{
  "client_name": "Sarah Johnson",
  "client_role": "Marketing Director",
  "client_company": "Northwind Studio",
  "testimonial_text": "<p>Setup took ten minutes and our reviews finally look professional.</p>",
  "rating": 5,
  "status": "approved",
  "is_featured": true,
  "categories": [
    3
  ],
  "custom_fields": {
    "project_type": "Website redesign"
  }
}

Responses

200 OK. data.id is the new testimonial.

{
  "success": true,
  "message": "Testimonial created successfully",
  "data": {
    "id": 42
  }
}
Field Type Meaning
data.id integer The new testimonial’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: client_name (blank) or testimonial_text (blank or under 10 characters).
400 rest_invalid_param rating outside 1 to 5, or status not one of the four values.
400 rest_missing_callback_param client_name or testimonial_text 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/testimonials" \
  -u "admin:$WP_APP_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{"client_name":"Sarah Johnson","client_role":"Marketing Director","client_company":"Northwind Studio","testimonial_text":"<p>Setup took ten minutes and our reviews finally look professional.</p>","rating":5,"status":"approved","is_featured":true,"categories":[3],"custom_fields":{"project_type":"Website redesign"}}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixatestimonial/v1/testimonials');
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([
        'client_name'      => 'Sarah Johnson',
        'client_role'      => 'Marketing Director',
        'client_company'   => 'Northwind Studio',
        'testimonial_text' => '<p>Setup took ten minutes and our reviews finally look professional.</p>',
        'rating'           => 5,
        'status'           => 'approved',
        'is_featured'      => true,
        'categories'       => [3],
        'custom_fields'    => [
            'project_type' => 'Website redesign',
        ],
    ]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixatestimonial/v1/testimonials', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic ' + btoa(`admin:${process.env.WP_APP_PASSWORD}`),
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ client_name: 'Sarah Johnson', client_role: 'Marketing Director', client_company: 'Northwind Studio', testimonial_text: '<p>Setup took ten minutes and our reviews finally look professional.</p>', rating: 5, status: 'approved', is_featured: true, categories: [3], custom_fields: { project_type: 'Website redesign' } }),
});
const { data } = await response.json();

Quick Links

Share