Key Takeaways
- The REST API exposes WordPress content as data endpoints
- Public content is accessible; private content requires authentication
- Standard HTTP methods: GET (read), POST (create), PUT (update), DELETE (remove)
- Custom endpoints extend the API for specific needs
- Opens possibilities for mobile apps, headless sites, and integrations
What Is the REST API?
Traditionally, WordPress generates HTML pages when visitors request URLs. The REST API adds another layer: it provides WordPress data in a structured format (JSON) that other applications can understand. Instead of "give me the blog page," you can say "give me the post data for post ID 42."
This transforms WordPress from a website builder into a content platform. Your WordPress content can power mobile apps, custom front-ends, external dashboards, automated workflows, and integrations with other systems—all while you manage content in the familiar WordPress admin.
WordPress as a Content Hub
The REST API separates content management from content display. WordPress handles content creation and storage. Other systems can consume that content and display it however they want. This is the foundation of "headless" WordPress.
REST API Basics
What REST Means
REST (Representational State Transfer) is an architecture style for web services. Key concepts:
- Resources: Things you can access (posts, users, pages)
- Endpoints: URLs that represent resources
- Methods: Actions you can perform (GET, POST, PUT, DELETE)
- JSON: Data format for requests and responses
HTTP Methods
| Method | Action | Example |
|---|---|---|
| GET | Read data | Retrieve a post |
| POST | Create new data | Create a new post |
| PUT/PATCH | Update existing data | Edit a post |
| DELETE | Remove data | Delete a post |
WordPress API Structure
The WordPress REST API follows a consistent URL pattern:
yoursite.com/wp-json/— API rootyoursite.com/wp-json/wp/v2/— WordPress core namespaceyoursite.com/wp-json/wp/v2/posts— Posts endpointyoursite.com/wp-json/wp/v2/posts/123— Specific post
Default Endpoints
WordPress provides endpoints for all core content types.
Content Endpoints
/wp/v2/posts— Blog posts/wp/v2/pages— Pages/wp/v2/media— Media library items/wp/v2/comments— Comments
Taxonomy Endpoints
/wp/v2/categories— Categories/wp/v2/tags— Tags
User Endpoints
/wp/v2/users— Users (public info only by default)/wp/v2/users/me— Current authenticated user
Settings and System
/wp/v2/settings— Site settings (authenticated)/wp/v2/types— Registered post types/wp/v2/statuses— Post statuses
Discover Available Endpoints
Making Requests
Using Your Browser
The simplest way to explore: just visit the URL. Open yoursite.com/wp-json/wp/v2/posts in your browser to see JSON data for your posts.
Using Command Line
# Get all posts
curl https://yoursite.com/wp-json/wp/v2/posts
# Get a specific post
curl https://yoursite.com/wp-json/wp/v2/posts/123
# Get posts with specific parameters
curl "https://yoursite.com/wp-json/wp/v2/posts?per_page=5&categories=10"
Common Parameters
per_page— Number of results (max 100)page— Page number for paginationsearch— Search termcategories— Filter by category IDtags— Filter by tag IDorderby— Sort field (date, title, etc.)order— Sort direction (asc, desc)
Understanding Responses
API responses include:
- Response body: The JSON data you requested
- Headers: Metadata including pagination info
- Status codes: Success (200), created (201), error (4xx, 5xx)
Authentication
Public content is accessible without authentication. Creating, editing, or deleting content requires authentication.
Authentication Methods
- Cookie authentication: For logged-in WordPress users (includes nonce)
- Application passwords: Built into WordPress 5.6+ for external apps
- OAuth: For third-party integrations (requires plugin)
- JWT tokens: Popular for headless setups (requires plugin)
Application Passwords
The simplest method for external applications:
-
Go to Users → Your Profile
Scroll to Application Passwords section.
-
Create new application password
Give it a descriptive name for the application using it.
-
Save the password
Copy it immediately—it won't be shown again.
-
Use with Basic Auth
Include username and application password in requests.
# Authenticated request with application password
curl --user "username:application_password" \
https://yoursite.com/wp-json/wp/v2/posts
Security Considerations
Creating and Updating Content
Creating a Post
curl --user "username:app_password" \
-X POST \
-H "Content-Type: application/json" \
-d '{
"title": "My New Post",
"content": "This is the post content.",
"status": "publish"
}' \
https://yoursite.com/wp-json/wp/v2/posts
Updating a Post
curl --user "username:app_password" \
-X PUT \
-H "Content-Type: application/json" \
-d '{
"title": "Updated Title"
}' \
https://yoursite.com/wp-json/wp/v2/posts/123
Deleting a Post
# Move to trash
curl --user "username:app_password" \
-X DELETE \
https://yoursite.com/wp-json/wp/v2/posts/123
# Permanently delete
curl --user "username:app_password" \
-X DELETE \
https://yoursite.com/wp-json/wp/v2/posts/123?force=true
Practical Use Cases
Mobile Applications
Build iOS or Android apps that read and write WordPress content. Your team manages content in WordPress; users access it through native apps.
Headless WordPress
Use WordPress for content management, but display content through a custom front-end built with React, Vue, or other frameworks.
Integrations
- Sync content to external systems
- Trigger workflows when content changes
- Import content from other platforms
- Connect with marketing automation tools
Custom Dashboards
Build specialized interfaces that pull WordPress data but display it differently than the admin area—executive dashboards, editorial workflows, client portals.
Static Site Generation
Use the API to pull content at build time for static site generators like Gatsby or Next.js. WordPress handles content; the static site provides speed and security.
Content Syndication
Publish once in WordPress, distribute everywhere. The API makes it easy to push content to multiple channels—social media, email platforms, partner sites—automatically.
Custom Endpoints
When built-in endpoints don't meet your needs, create custom ones.
Registering Custom Endpoints
add_action( 'rest_api_init', function() {
register_rest_route( 'myplugin/v1', '/featured-content', array(
'methods' => 'GET',
'callback' => 'get_featured_content',
'permission_callback' => '__return_true',
));
});
function get_featured_content( $request ) {
// Your logic to fetch featured content
$data = array(
'title' => 'Featured Item',
'url' => 'https://example.com',
);
return new WP_REST_Response( $data, 200 );
}
When to Create Custom Endpoints
- Combining data from multiple sources
- Complex queries not possible with default endpoints
- Exposing custom post type data
- Creating simplified responses for specific apps
Getting Started
The REST API opens WordPress to possibilities beyond traditional websites. You don't need to use it for everything—sometimes a standard WordPress site is exactly right. But understanding the API prepares you for projects that need more flexibility.
Start by exploring the API on your own site. Visit /wp-json/ and browse the endpoints. Try fetching posts with different parameters. Experiment with tools like Postman. The API is already there, waiting to be used.
Frequently Asked Questions
Is the REST API enabled by default in WordPress?
Is the WordPress REST API secure?
Can I use the REST API without knowing how to code?
What's the difference between REST API and GraphQL for WordPress?
Need help with WordPress API development?
I help organizations build custom WordPress integrations and headless solutions. Let's discuss your technical requirements.