0
0
Wordpressframework~5 mins

Default API endpoints in Wordpress

Choose your learning style9 modes available
Introduction

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.

You want to show your blog posts on a mobile app.
You need to get user info from your site for another tool.
You want to update content on your site from an external program.
You want to list categories or tags on a custom website.
You want to check site data without logging into WordPress admin.
Syntax
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.

Examples
Gets a list of all blog posts.
Wordpress
/wp-json/wp/v2/posts
Gets the blog post with ID 10.
Wordpress
/wp-json/wp/v2/posts/10
Gets a list of all pages on the site.
Wordpress
/wp-json/wp/v2/pages
Gets a list of users (if allowed by permissions).
Wordpress
/wp-json/wp/v2/users
Sample Program

This JavaScript code fetches all posts from a WordPress site using the default API endpoint and prints them in the browser console.

Wordpress
fetch('https://example.com/wp-json/wp/v2/posts')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));
OutputSuccess
Important Notes

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.

Summary

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.