Skip to content
Drivers/WordPress REST API

WordPress REST API

driverwordpress5/8 capabilities

Import the driver directly so every other driver tree-shakes away.

wordpress.ts
import { WORDPRESS_DRIVER, QubeeStore, QueryBuilder, Paginator } from '@qubeejs/core';
const store = new QubeeStore();
const qb = new QueryBuilder(store, WORDPRESS_DRIVER.createRequestStrategy('query'));
const paginator = new Paginator(
store,
WORDPRESS_DRIVER.createResponseStrategy(),
WORDPRESS_DRIVER.createResponseOptions({}),
);
qb.setResource('articles')
.addFilter('status', 'published')
.addSort('createdAt', SortEnum.DESC)
.setLimit(25)
.generateUri();

Produces:

/articles?status=published&orderby=createdAt&order=desc&page=1&per_page=25
Capability Supported
Filters ✅
Operators —
Sort ✅
Select ✅
Fields —
Includes ✅
Search ✅
Embedded —

The totals travel in the response headers, so pass them as the second argument:

const response = await fetch(`https://example.com/api${uri}`);
const page = paginator.paginate(await response.json(), response.headers);
page.data; // rows
page.total; // total rows the backend reported
page.lastPage; // final page number