---
description: Steps for create Wordpress REST API
---

# Create WordPress REST API

**STEPS FOR CREATE WORDPRESS REST API**

1.  Download WordPress plugin for REST API from below link

    &#x20;[https://wordpress.org/plugins/rest-api/#description](https://wordpress.org/plugins/rest-api/#description)
2. Login to WordPress admin panel through **SITE\_URL/wp-login.php** \
   **Then in sidebar of dashboard**
   1. Go to option ‘**PLUGINS**’
   2. Click on **Add New**
   3. Upload **Plugin**
   4. upload **downloaded** **plugin**
   5. **Install** Now
   6. **Active** that plugin                                                        &#x20;
3. Then check below link for API (i.e, **SITE\_URL/wp-json/wp/v2/posts** )\
   &#x20;You will get list of posts which are added in website\
   &#x20;[http://itechnotion.in/wp-news/wp-json/wp/v2/posts](http://itechnotion.in/wp-news/wp-json/wp/v2/posts)
4. There is list of APIs for getting different types of data (i.e, posts, categories, comments, etc.)\
   &#x20;That list I have attached at end of this document.
5. If there is need to add extra fields which aren’t providing by default API,\
   &#x20;then you need to add custom function for adding extra fields in below file\
   &#x20;**/wp-content/themes/themename/functions.php**\
   &#x20;I have added some custom functions there for adding extra needed fields.
6. And for contact\_us form & add comment form,\
   &#x20;I have written two APIs there in /api folder.

**LIST OF REST APIs**

**1) For getting all posts(GET method)**

&#x20;               SITE\_URL/wp-json/wp/v2/posts/ or

&#x20;               SITE\_URL/wp-json/wp/v2/posts/?page=1

&#x20;               **For fetching next posts**

&#x20;               SITE\_URL/wp-json/wp/v2/posts/?page=2

&#x20;                **For getting limited posts**(i.e, for getting only two records)

&#x20;               SITE\_URL/wp-json/wp/v2/posts/?page=1\&per\_page=2

**2) For getting post by post id(GET method)**

&#x20;                 SITE\_URL/wp-json/wp/v2/posts/577

**3) For getting all categories: (GET method)**

&#x20;                SITE\_URL/wp-json/wp/v2/categories

**4) For getting category by category id: (GET method)**

&#x20;                SITE\_URL/wp-json/wp/v2/categories/162

**5) For getting all posts by category id: (GET method)**

&#x20;               SITE\_URL/wp-json/wp/v2/posts?categories=162

**6) Search posts by keyword: (GET method)**

&#x20;              SITE\_URL/wp-json/wp/v2/posts/?search=world

**7) For getting comments for post: (GET method)**

&#x20;              SITE\_URL/wp-json/wp/v2/comments?post=553

**Link for adding custom APIs for add comment & contact us:**

&#x20;            [**http://itechnotion.in/wp-plugin/api.zip**](http://itechnotion.in/wp-plugin/api.zip)&#x20;

[**Download zip**](http://itechnotion.in/wp-plugin/api.zip) from above link and put in root directory of server then unzip it in root directory. It will add that custom API files in api directory.

**8) For contact us: (POST method)**

&#x20;              SITE\_URL/api/contact\_us.php

&#x20;             **Post parameters:**

&#x20;              1\) name

&#x20;              2\) email

&#x20;              3\) message

**9) For adding comment: (POST method)**

&#x20;             SITE\_URL/api/comment.php

&#x20;            **Post parameters:**

&#x20;             1\) post\_id // 617

&#x20;             2\) comment\_author // itech

&#x20;             3\) comment\_author\_email // itech@test.com

&#x20;             4\) comment\_content // test comment

&#x20;             5\) user\_id

// If adding comment without login then pass zero as \`user\_id\`

else pass value of \`user\_id\`

**10) Custom field adding**

A. Download plugin from [http://itechnotion.in/wp-plugin/WpNewsCustomAPI.zip](http://itechnotion.in/wp-plugin/WpNewsCustomAPI.zip)

B. Setup Plugin on your website.
