REST API Endpoints
REST API Endpoints provides custom WordPress REST API endpoints with efficient pagination to securely expose and manage WordPress data for external applications.
Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/malekimtiyaj/advanced-wp-rest-api-manager/archive/refs/heads/main.zipA WordPress plugin that provides custom REST API endpoints with efficient pagination to securely expose and manage WordPress data for external applications.
Features
- Efficient Pagination: Token-based pagination using page tokens instead of offset-based pagination, providing better performance and consistency
- Advanced Filtering: Search, filter by category, author, date range, and MIME type for precise data retrieval
- Complete CRUD Operations: Full Create, Read, Update, Delete support for posts and pages
- Media Support: Complete media/attachment endpoint with image sizes, file metadata, and filtering
- API Discovery: Built-in discovery endpoint that lists all available endpoints, methods, and documentation
- Enhanced Error Messages: Helpful error messages with suggestions and documentation links
- Response Metadata: Includes API version, response time, and total count in responses
- Secure Authentication: Built-in permission checks supporting Application Passwords, OAuth, and Cookie authentication
- ACF Integration: Optional Advanced Custom Fields support with security filtering
- RESTful Design: Follows WordPress REST API standards and conventions
Installation
- Upload the
rest-api-pluginfolder to/wp-content/plugins/directory - Activate the plugin through the 'Plugins' menu in WordPress
- The REST API endpoints will be available at
/wp-json/rest-api-plugin/v1/
Endpoints
All endpoints require user authentication and the read capability.
Base URL
/wp-json/rest-api-plugin/v1/
Available Endpoints
Posts
GET /wp-json/rest-api-plugin/v1/posts
Pages
GET /wp-json/rest-api-plugin/v1/pages
Users
GET /wp-json/rest-api-plugin/v1/users
Comments
GET /wp-json/rest-api-plugin/v1/comments
Categories
GET /wp-json/rest-api-plugin/v1/categories
Tags
GET /wp-json/rest-api-plugin/v1/tags
Media/Attachments
GET /wp-json/rest-api-plugin/v1/media
GET /wp-json/rest-api-plugin/v1/media/{id}
API Discovery
GET /wp-json/rest-api-plugin/v1/
Returns information about all available endpoints, authentication methods, and API documentation.
Query Parameters
Common Parameters (All Endpoints)
page_token(string, optional): Base64-encoded page token for pagination. Omit for the first page.per_page(integer, optional): Maximum number of items to return per page. Default: 10, Maximum: 100order(string, optional): Order direction. Options:ascordesc. Default:desc
Posts/Pages Filtering Parameters
search(string, optional): Search query to filter posts/pages by title or contentcategory(integer|string, optional): Filter posts by category ID or slugauthor(integer, optional): Filter posts/pages by author IDdate_after(string, optional): Filter items published after this date (YYYY-MM-DD format)date_before(string, optional): Filter items published before this date (YYYY-MM-DD format)
Media Filtering Parameters
mime_type(string, optional): Filter media by MIME type (e.g., "image/jpeg", "image/*" for all images)date_after(string, optional): Filter media uploaded after this date (YYYY-MM-DD format)date_before(string, optional): Filter media uploaded before this date (YYYY-MM-DD format)
Usage Examples
Get First Page of Posts
curl -X GET "https://yoursite.com/wp-json/rest-api-plugin/v1/posts?per_page=20" \
-H "Authorization: Bearer YOUR_AUTH_TOKEN"
Get Next Page Using Page Token
curl -X GET "https://yoursite.com/wp-json/rest-api-plugin/v1/posts?per_page=20&page_token=MTIz" \
-H "Authorization: Bearer YOUR_AUTH_TOKEN"
Get Users in Ascending Order
curl -X GET "https://yoursite.com/wp-json/rest-api-plugin/v1/users?order=asc&per_page=50" \
-H "Authorization: Bearer YOUR_AUTH_TOKEN"
Search Posts
curl -X GET "https://yoursite.com/wp-json/rest-api-plugin/v1/posts?search=wordpress&per_page=20" \
-H "Authorization: Bearer YOUR_AUTH_TOKEN"
Filter Posts by Category and Date Range
curl -X GET "https://yoursite.com/wp-json/rest-api-plugin/v1/posts?category=5&date_after=2024-01-01&date_before=2024-12-31" \
-H "Authorization: Bearer YOUR_AUTH_TOKEN"
Get Images Only
curl -X GET "https://yoursite.com/wp-json/rest-api-plugin/v1/media?mime_type=image/*&per_page=50" \
-H "Authorization: Bearer YOUR_AUTH_TOKEN"
API Discovery
curl -X GET "https://yoursite.com/wp-json/rest-api-plugin/v1/" \
-H "Authorization: Bearer YOUR_AUTH_TOKEN"
Response Format
All endpoints return responses in the following format:
{
"data": [
{
// Item data here
}
],
"pagination": {
"has_next": true,
"next_token": "base64_encoded_token"
},
"meta": {
"version": "1.0.0",
"response_time_ms": 45.23,
"total_found": 150
}
}
The meta object includes:
version: Plugin versionresponse_time_ms: Response time in millisecondstotal_found: Total number of items matching the query (for filtered endpoints)
Posts Response Example
{
"data": [
{
"id": 123,
"title": "Post Title",
"content": "Post content...",
"excerpt": "Post excerpt...",
"slug": "post-slug",
"date": "2024-01-01 12:00:00",
"modified": "2024-01-02 12:00:00",
"author": {
"id": 1,
"name": "Author Name"
},
"status": "publish",
"type": "post",
"permalink": "https://yoursite.com/post-slug/"
}
],
"pagination": {
"has_next": true,
"next_token": "MTIz"
}
}
Pagination
Efficient pagination provides several advantages over traditional offset-based pagination:
- Performance: More efficient for large datasets as it doesn't require counting all previous records
- Consistency: Avoids issues with data changing between page requests
- Scalability: Better suited for high-traffic applications
How It Works
- Make your first request without a page_token parameter
- The response includes a
next_tokenvalue in the pagination object - Use the
next_tokenvalue as thepage_tokenparameter in your next request - Continue until
has_nextisfalse
Authentication
This plugin requires WordPress user authentication. You can authenticate using:
- Application Passwords (WordPress 5.6+): Generate an application password in your user profile
- Cookie Authentication: For same-domain requests
- OAuth: If you have an OAuth plugin installed
Example with Application Password:
curl -X GET "https://yoursite.com/wp-json/rest-api-plugin/v1/posts" \
-u "username:application_password"
Security
- All endpoints require user authentication
- Users must have the
readcapability - Page token values are base64-encoded to prevent tampering
- Input validation on all query parameters
Requirements
- WordPress 5.0 or higher
- PHP 7.2 or higher
- REST API enabled (default in WordPress 4.7+)
License
GPL v2 or later
Support
For issues, questions, or contributions, please visit the plugin repository.