Contents
Create Custom Field - Plugixa Testimonial
POST /plugixatestimonial/v1/custom-fields
Define a new custom field for testimonials.
Administrators only: the user needs WordPress’s manage_options capability. No plugin capability opens this route.
Request
POST https://your-site.example/wp-json/plugixatestimonial/v1/custom-fields
Request body
Content type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
field_label |
string |
Yes | Plain text, must not be blank. |
field_key |
string |
No | Lower-case letters, digits and _. Made from the label when empty. Must not exist yet, in any language. |
field_type |
string |
No | text (the default), textarea, url, number, date, select, checkbox or color. |
field_options |
string[] |
See below | The choices. Required, with at least one, for a select field. A JSON-encoded array string is accepted too. |
placeholder |
string |
No | Placeholder text on the form. |
is_required |
boolean |
No | Defaults to false. |
show_in_frontend |
boolean |
No | Defaults to true. |
menu_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 field this one translates. |
Values are then stored per testimonial through the custom_fields object of Create Testimonial and the public Submit Testimonial.
{
"field_label": "Project type",
"field_key": "project_type",
"field_type": "select",
"field_options": [
"Website redesign",
"Branding",
"SEO"
],
"show_in_frontend": true
}
Responses
200 OK. data.id is the new field.
{
"success": true,
"message": "Custom field created successfully",
"data": {
"id": 5
}
}
| Field | Type | Meaning |
|---|---|---|
data.id |
integer |
The new field’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: field_label, field_key (bad characters, or “This field key already exists”), field_type or field_options. |
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/custom-fields" \
-u "admin:$WP_APP_PASSWORD" \
-H "Content-Type: application/json" \
-d '{"field_label":"Project type","field_key":"project_type","field_type":"select","field_options":["Website redesign","Branding","SEO"],"show_in_frontend":true}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixatestimonial/v1/custom-fields');
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([
'field_label' => 'Project type',
'field_key' => 'project_type',
'field_type' => 'select',
'field_options' => ['Website redesign', 'Branding', 'SEO'],
'show_in_frontend' => true,
]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixatestimonial/v1/custom-fields', {
method: 'POST',
headers: {
'Authorization': 'Basic ' + btoa(`admin:${process.env.WP_APP_PASSWORD}`),
'Content-Type': 'application/json',
},
body: JSON.stringify({ field_label: 'Project type', field_key: 'project_type', field_type: 'select', field_options: ['Website redesign', 'Branding', 'SEO'], show_in_frontend: true }),
});
const { data } = await response.json();
Quick Links
Share