Skip to content

Custom Post Type API

import { Aside } from ‘@astrojs/starlight/components’;

The Loopress plugin registers read-only REST endpoints for any registered custom post type. This lets you query CPT content without building a custom endpoint or dealing with multiple requests for meta.

  • The post type must be registered with WordPress (via a theme, plugin, or code snippet)
  • Administrator role (manage_options capability)

List all posts of a given post type. {post_type} must be a registered post type slug.

Example:

Terminal window
curl -H "X-WP-Nonce: <nonce>" \
https://example.com/wp-json/lps/v1/cpt/product

Response:

[
{
"id": 42,
"title": "My Product",
"content": "Product description...",
"status": "publish",
"created_at": "2024-01-15 10:00:00",
"updated_at": "2024-03-01 14:30:00",
"meta": {
"_price": ["29.99"],
"_sku": ["PROD-001"]
}
}
]

Retrieve a single post by ID. Returns 404 if the post does not exist or belongs to a different post type.

Example:

Terminal window
curl -H "X-WP-Nonce: <nonce>" \
https://example.com/wp-json/lps/v1/cpt/product/42
StatusCause
400{post_type} is not a registered post type
403Caller does not have manage_options capability
404Post not found or wrong post type
  • Post meta is returned via get_post_meta(), all meta keys for the post are included
  • Posts with any status (publish, draft, private, etc.) are returned
  • This endpoint is read-only; creating or updating posts is not supported