Contents
On this page

Preview Permastructure - Plugixa Permalink Manager

POST /plugixa-permalink-manager/v1/permastructures/preview

Show the addresses a pattern would give a few real items, beside the addresses they have now. Nothing is saved.

Needs the plugixa_permalink_manager_view capability.

Request

POST https://your-site.example/wp-json/plugixa-permalink-manager/v1/permastructures/preview

Request body

Content type: application/json

Field Type Required Description
kind string Yes post_type or taxonomy
name string Yes A managed post type or taxonomy
pattern string No The pattern to try. Empty previews the WordPress structure
append_slug boolean No Defaults to true. Only a JSON false turns it off
language string No One of the site’s languages

The samples are the five most recent published posts of the type (the front page left out), or for a taxonomy the five terms with the most items.

{
  "kind": "post_type",
  "name": "product",
  "pattern": "gear/%product_cat%/%postname%"
}

Responses

200 OK.

{
  "success": true,
  "data": {
    "pattern": "gear/%product_cat%/%postname%",
    "samples": [
      {
        "id": 36,
        "title": "Skyline 2 Tent",
        "current": "shop/tents/skyline-2",
        "preview": "gear/tents/skyline-2",
        "error": null
      }
    ],
    "unknown": []
  }
}
Field Type Meaning
data.pattern string The pattern after cleaning: only letters, digits, %, _, ., - and / are kept
data.samples[].current string|null The item’s address now
data.samples[].preview string|null The address the pattern would give it, null on error
data.samples[].error string|null Why the address could not be built
data.unknown array Tags in the pattern that this type does not offer

Errors

Status Code When
404 plugixa_permalink_manager_not_found kind and name are not a managed content type.
422 plugixa_permalink_manager_invalid_language language is not one of the site’s languages.

Plus the errors every endpoint can return.

Examples

curl -s -X POST "https://your-site.example/wp-json/plugixa-permalink-manager/v1/permastructures/preview" \
  -u "admin:$WP_APP_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{"kind":"post_type","name":"product","pattern":"gear/%product_cat%/%postname%"}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-permalink-manager/v1/permastructures/preview');
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([
        'kind'    => 'post_type',
        'name'    => 'product',
        'pattern' => 'gear/%product_cat%/%postname%',
    ]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const auth = 'Basic ' + btoa(`admin:${process.env.WP_APP_PASSWORD}`);
const response = await fetch('https://your-site.example/wp-json/plugixa-permalink-manager/v1/permastructures/preview', {
  method: 'POST',
  headers: {
    'Authorization': auth,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    kind: 'post_type',
    name: 'product',
    pattern: 'gear/%product_cat%/%postname%',
  }),
});
const { data } = await response.json();

Quick Links

Share