> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gvb-staging.co.uk/llms.txt
> Use this file to discover all available pages before exploring further.

# WordPress voucher feed

> Show vouchers from a shop on a WordPress site.

Fetch vouchers on the server, cache them, and link each one to its storefront page with `url`. Never call the API from the browser: the bearer token would be visible to every visitor, and cross-origin browser requests are not enabled.

## Choose which vouchers to show

* **A category**: pass `category_id` to `/tenants/{tenant}/catalog/vouchers`. The response follows the positions saved in that category and returns each position as `sort_order`.
* **A hand-picked list**: create a category in GVB, mark it **Hidden**, and add the vouchers to it. A hidden category stays out of the shop's own listings but still works as a `category_id` filter. Find its identifier with `/catalog/categories?include_hidden=true`.
* **Best sellers**: pass `best_sellers=true` and order by `best_seller_rank`. The list follows the shop's Best Sellers setting, so it is empty when that setting is off.

Vouchers that are hidden, disabled, or outside their schedule are never returned.

## Example

Store the token outside the theme, for example as a constant in `wp-config.php`. The transient keeps the feed for 15 minutes so page views do not count against the rate limit.

```php theme={null}
function gvb_vouchers(int $tenant_id, int $category_id): array
{
    $cache_key = "gvb_vouchers_{$tenant_id}_{$category_id}";
    $vouchers = get_transient($cache_key);

    if (is_array($vouchers)) {
        return $vouchers;
    }

    $vouchers = [];
    $cursor = null;

    do {
        $response = wp_remote_get(add_query_arg(array_filter([
            'category_id' => $category_id,
            'cursor' => $cursor,
        ]), GVB_API_BASE_URL."/tenants/{$tenant_id}/catalog/vouchers"), [
            'headers' => [
                'Accept' => 'application/json',
                'Authorization' => 'Bearer '.GVB_API_TOKEN,
            ],
        ]);

        if (wp_remote_retrieve_response_code($response) !== 200) {
            return [];
        }

        $page = json_decode(wp_remote_retrieve_body($response), true);
        $vouchers = array_merge($vouchers, $page['data']);
        $cursor = $page['next_cursor'];
    } while ($cursor !== null);

    set_transient($cache_key, $vouchers, 15 * MINUTE_IN_SECONDS);

    return $vouchers;
}
```

Render each voucher from `title`, `summary`, `image_url`, and `from_sale_price` (falling back to `from_price`, `sale_price`, then `price`), and link it to `url`. Escape every value on output.

## Token

Create a token in **API Access** with `view_vouchers`, plus `view_categories` if the site reads categories. It needs no other permission.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.