Default API endpoints let you get or send data to your WordPress site easily. They help connect your site with other apps or websites without extra setup.
Default API endpoints in Wordpress
/wp-json/wp/v2/{type}/{id}{type} is the kind of content like posts, pages, or users.
{id} is optional and means a specific item number.
/wp-json/wp/v2/posts
/wp-json/wp/v2/posts/10/wp-json/wp/v2/pages
/wp-json/wp/v2/users
This JavaScript code fetches all posts from a WordPress site using the default API endpoint and prints them in the browser console.
fetch('https://example.com/wp-json/wp/v2/posts') .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error));
Default endpoints follow a standard URL pattern starting with /wp-json/wp/v2/.
Some data may require you to be logged in or have permissions.
You can add query parameters to filter or sort results, like ?per_page=5 to get 5 items.
Default API endpoints let you access WordPress data easily via URLs.
They use a simple pattern with content type and optional ID.
You can use them to connect your site with other apps or tools without extra coding.
Practice
Solution
Step 1: Understand what API endpoints do
API endpoints provide a way to get or send data through URLs.Step 2: Identify the role of default WordPress endpoints
They let you access WordPress content like posts or users easily without extra coding.Final Answer:
To allow easy access to WordPress data via URLs -> Option AQuick Check:
Default API endpoints = easy data access [OK]
- Thinking endpoints create themes
- Confusing endpoints with user management
- Assuming endpoints handle SEO
Solution
Step 1: Recall the WordPress REST API base URL
The base URL for WordPress REST API is/wp-json/wp/v2/.Step 2: Identify the correct endpoint for posts
The posts endpoint isposts, so full URL is/wp-json/wp/v2/posts.Final Answer:
/wp-json/wp/v2/posts -> Option DQuick Check:
Posts endpoint = /wp-json/wp/v2/posts [OK]
- Using admin URLs instead of API URLs
- Confusing API version or path
- Using incorrect folder paths
/wp-json/wp/v2/posts/10 in a WordPress site?Solution
Step 1: Understand the endpoint pattern
The URL/wp-json/wp/v2/posts/{id}fetches a single post by its ID.Step 2: Interpret the given URL
Here, ID is 10, so it returns the post with ID 10 in JSON format.Final Answer:
Returns the post with ID 10 in JSON format -> Option AQuick Check:
Single post URL returns that post [OK]
- Thinking it returns all posts except one
- Assuming ID is invalid in URL
- Expecting a redirect instead of JSON
/wp-json/wp/v2/users but get a 401 Unauthorized error. What is the likely cause?Solution
Step 1: Check endpoint access rules
Users endpoint requires authentication because user data is sensitive.Step 2: Analyze the error 401 Unauthorized
This error means the request lacks valid credentials to access the resource.Final Answer:
You need proper authentication to access users endpoint -> Option CQuick Check:
401 error = authentication needed [OK]
- Thinking users endpoint is missing
- Assuming URL version is wrong
- Confusing HTTP methods
Solution
Step 1: Identify correct query parameters for category and status
WordPress REST API usescategoriesfor category IDs andstatusfor post status.Step 2: Match parameters with correct values
Category ID is 5, and published posts usestatus=publish.Final Answer:
/wp-json/wp/v2/posts?categories=5&status=publish -> Option BQuick Check:
categories=5 and status=publish are correct params [OK]
- Using wrong parameter names like category or cat
- Using status=published instead of publish
- Mixing post_status with status
Ready to prove it?
Pass the test and this pattern moves unknown
