Title: Call WordPress rest api using links/url
Last modified: August 22, 2017

---

# Call WordPress rest api using links/url

 *  [tejasbramhecha](https://wordpress.org/support/users/tejasbramhecha/)
 * (@tejasbramhecha)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/)
 * Hi,
 * I was in need to fetch data using page link/url that is available to me. Can 
   we call wordpress rest api using link? If yes, may I know how can that be done?
   Shall appreciate responses.
    Thanks

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/page/2/?output_format=md)

 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/#post-9429938)
 * You can link to a REST API endpoint, but you’re just going to get a JSON response.
 * What are you actually trying to accomplish?
    -  This reply was modified 8 years, 9 months ago by [Jacob Peattie](https://wordpress.org/support/users/jakept/).
 *  Thread Starter [tejasbramhecha](https://wordpress.org/support/users/tejasbramhecha/)
 * (@tejasbramhecha)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/#post-9430026)
 * Hello [@jakept](https://wordpress.org/support/users/jakept/),
 * What I’m trying here is to get json data from wordpress but to call wp rest api,
   I need something like tag/category/id, right? but all that I have is link/url
   so I am just asking if I can call wp rest api using that link which is available
   to me & get json data? If yes, how
 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/#post-9430130)
 * No, you can’t. If you have the *slug* of the category, you would request categories
   with that slug using the categories endpoint:
 *     ```
       /wp/v2/categories?slug=category-slug-you-want-id-for
       ```
   
 * And then get the ID of the category out of that response, then use the posts 
   endpoint to get posts with that category:
 *     ```
       /wp/v2/posts?categories=category-id-that-you-found
       ```
   
    -  This reply was modified 8 years, 9 months ago by [Jacob Peattie](https://wordpress.org/support/users/jakept/).
 *  Thread Starter [tejasbramhecha](https://wordpress.org/support/users/tejasbramhecha/)
 * (@tejasbramhecha)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/#post-9449561)
 * Hi [@jakept](https://wordpress.org/support/users/jakept/),
 * May I know if we can retrieve posts using title?
    e.g. /wp/v2/posts?title=Testing
   Cloud Security
 * or is there any way to do this?
    Thanks
 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/#post-9449568)
 * [@tejasbramhecha](https://wordpress.org/support/users/tejasbramhecha/) You can
   see the ways you can retrieve pages with the API in the documentation: [https://developer.wordpress.org/rest-api/reference/pages/#list-pages](https://developer.wordpress.org/rest-api/reference/pages/#list-pages)
 * Title isn’t one of them. You could use `search` to search for a page by title,
   but you couldn’t 100% guarantee it’s the page you want.
 *  Thread Starter [tejasbramhecha](https://wordpress.org/support/users/tejasbramhecha/)
 * (@tejasbramhecha)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/#post-9475262)
 * Hi [@jakept](https://wordpress.org/support/users/jakept/),
 * I tried the solution that you gave to me. I tried to get posts using following
   api call: /wp/v2/posts?categories=category-id-that-I-found but this returned 
   me something like this “Unexpected ‘<‘”. Would please let me know what’s wrong
   here?
 * Thanks
 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/#post-9475292)
 * That error just means there’s a syntax error somewhere in your code. It would
   have given you a line number in your code to look at. Go to it and check for 
   typos.
 *  Thread Starter [tejasbramhecha](https://wordpress.org/support/users/tejasbramhecha/)
 * (@tejasbramhecha)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/#post-9475316)
 * Hi [@jakept](https://wordpress.org/support/users/jakept/),
 * I’m running this directly on postman. There’s no code. The simple aim that I 
   have here is to retrieve posts that have this category id. I have checked my 
   categories too to ensure that the id I’m using is there in dataset.
 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/#post-9475324)
 * Doesn’t change the fact that “Unexpected …” is a syntax error. There’s still 
   code on the WordPress site you’re requesting from, so the issue must be there.
 *  Thread Starter [tejasbramhecha](https://wordpress.org/support/users/tejasbramhecha/)
 * (@tejasbramhecha)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/#post-9475555)
 * Hi [@jakept](https://wordpress.org/support/users/jakept/),
 * I could fetch posts by using category id now. But for some ids it shows null 
   to me even when there is data in backend with that category id. Would you please
   let me know why is it happening so?
 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/#post-9476105)
 * If you’re getting null it’s because there aren’t any posts in that category. 
   I can’t help any more than that without a URL.
 * EDIT: Put it this way:
    `http://website.com/wp-json/wp/v2/posts?categories=1`
   Should return the same posts as `http://website.com/?cat=1` (But in JSON, obviously)
 * So make sure you’re also not getting any posts with the second URL.
    -  This reply was modified 8 years, 9 months ago by [Jacob Peattie](https://wordpress.org/support/users/jakept/).
    -  This reply was modified 8 years, 9 months ago by [Jacob Peattie](https://wordpress.org/support/users/jakept/).
    -  This reply was modified 8 years, 9 months ago by [Jacob Peattie](https://wordpress.org/support/users/jakept/).
 *  Thread Starter [tejasbramhecha](https://wordpress.org/support/users/tejasbramhecha/)
 * (@tejasbramhecha)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/#post-9478217)
 * Hi [@jakept](https://wordpress.org/support/users/jakept/),
 * I want to retrieve portfolio data from my website. Is there any way that I can
   make a call to wp-rest-api & get it? If yes, can you please let me know how? 
   If no, can we add custom post type as portfolio in wp-rest-api code & make it
   work? Unfortunately, I’m unable to find proper documentation regarding custom
   post types. Shall be grateful if you can help somehow.
    Thanks
 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/#post-9478651)
 * Look at the documentation for [`register_post_type()`](https://developer.wordpress.org/reference/functions/register_post_type/),
   particularly the properties for `show_in_rest` and `rest_base`. If the post type
   has custom fields you need to access, look at [`register_meta()`](https://developer.wordpress.org/reference/functions/register_meta/).
 *  Thread Starter [tejasbramhecha](https://wordpress.org/support/users/tejasbramhecha/)
 * (@tejasbramhecha)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/#post-9572601)
 * Hi [@jakept](https://wordpress.org/support/users/jakept/),
 * I’m now able to access portfolio data using wp rest api but the json that I’m
   getting is not having any category id/tag mentioned in it. Will you please let
   me know what can be done to make sure that I get category id/tag?
 * I have written code as following:
 *     ```
       /**
        * Add REST API support to an already registered post type.
        */
       add_action( 'init', 'my_custom_post_type_rest_support', 25 );
       function my_custom_post_type_rest_support() {
         global $wp_post_types;
   
         //be sure to set this to the name of your post type!
         $post_type_name = 'startapp_portfolio';
         if( isset( $wp_post_types[ $post_type_name ] ) ) {
           $wp_post_types[$post_type_name]->show_in_rest = true;
           $wp_post_types[$post_type_name]->rest_base = $post_type_name;
           $wp_post_types[$post_type_name]->rest_controller_class = 'WP_REST_Posts_Controller';
   
         }
       }
       ```
   
 * Thanks,
    -  This reply was modified 8 years, 8 months ago by [tejasbramhecha](https://wordpress.org/support/users/tejasbramhecha/).
 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/#post-9572627)
 * Taxonomies also need to be set to show in REST: [https://developer.wordpress.org/reference/functions/register_taxonomy/](https://developer.wordpress.org/reference/functions/register_taxonomy/)

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/page/2/?output_format=md)

The topic ‘Call WordPress rest api using links/url’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 16 replies
 * 2 participants
 * Last reply from: [tejasbramhecha](https://wordpress.org/support/users/tejasbramhecha/)
 * Last activity: [8 years, 8 months ago](https://wordpress.org/support/topic/call-wordpress-rest-api-using-linksurl/page/2/#post-9573024)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
