Contents
On this page

Create Custom Field - Plugixa FAQ

POST /plugixa-faq/v1/custom-fields

Add a custom field that every FAQ can carry a value for.

Administrators only: the user needs the plugixa_faq_settings capability or WordPress’s manage_options. Needs Plugixa FAQ Pro: the free build does not register this route, so it answers 404 there.

Request

POST https://your-site.example/wp-json/plugixa-faq/v1/custom-fields

Request body

Content type: application/json

Field Type Required Description
field_key string Yes Machine name, unique (per language with WPML or Polylang). Lower-cased; only letters, digits, _ and - are kept.
field_label string Yes Label shown to editors and visitors.
field_type string No text (the default), textarea, url, number, date, select, checkbox or color. Anything else becomes text.
field_options array No The choices of a select field.
placeholder string No Placeholder text.
is_required boolean No Whether editors must fill it in. Defaults to false.
show_in_frontend boolean No Whether visitors see the value. Defaults to true.
language_code string No With WPML or Polylang active only: the field’s language.
translation_group string No With WPML or Polylang active only: join an existing translation group.

The new field is placed last. menu_order cannot be set here: use Reorder Custom Fields.

{
  "field_key": "warranty",
  "field_label": "Warranty",
  "field_type": "text",
  "placeholder": "e.g. 2 years"
}

Responses

200 OK. data.id is the new field.

{
  "success": true,
  "message": "Custom field created",
  "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”: field_key or field_label is missing or empty. data.errors names the field.
400 rest_error “A field with this key already exists”.
500 rest_error The database refused the row.

Plus the errors every endpoint can return.

Examples

curl -s -X POST "https://your-site.example/wp-json/plugixa-faq/v1/custom-fields" \
  -u "admin:$WP_APP_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{"field_key":"warranty","field_label":"Warranty","field_type":"text","placeholder":"e.g. 2 years"}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-faq/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_key'   => 'warranty',
        'field_label' => 'Warranty',
        'field_type'  => 'text',
        'placeholder' => 'e.g. 2 years',
    ]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixa-faq/v1/custom-fields', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic ' + btoa(`admin:${process.env.WP_APP_PASSWORD}`),
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ field_key: 'warranty', field_label: 'Warranty', field_type: 'text', placeholder: 'e.g. 2 years' }),
});
const { data } = await response.json();

Quick Links

Share