Title: Access via REST API
Last modified: April 10, 2019

---

# Access via REST API

 *  Resolved [dusang](https://wordpress.org/support/users/dusang/)
 * (@dusang)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/)
 * Hello,
    as far as I know, WordPress REST API will return only “modified” and “
   modified_gmt” (both of them are dates) for posts. I’d like to have something 
   like “modified_by” to return the user who modified a post. I believe this plugin
   adds this functionality as this is written in the description: Allows you to 
   display last modified author info in posts, pages. Is it possible to get the 
   information about last modified author via REST API? And if so, how is it possible
   please?
 * Thanks.
 * Dusan

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

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

 *  Plugin Author [Sayan Datta](https://wordpress.org/support/users/infosatech/)
 * (@infosatech)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/#post-11412628)
 * Hi [@dusang](https://wordpress.org/support/users/dusang/)
 * May I know what you want to do by using last modified author name from REST API?
 * Thanks!
    -  This reply was modified 7 years, 1 month ago by [Sayan Datta](https://wordpress.org/support/users/infosatech/).
 *  Thread Starter [dusang](https://wordpress.org/support/users/dusang/)
 * (@dusang)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/#post-11412700)
 * Hi Sayan,
 * We are using KnowAll theme (Knowledge base). I created a utility to generate 
   a report of Knowledge Base articled modified in the last week, which contains
   Subject, Creation Date, Created By and Modified Date. The only information missing
   here is Modified By. I’m getting this information via WordPress REST API.
 * So that’s why I’m wondering if we install your plugin to get Modified By (the
   last person who modified Knowledge Base article), if I’ll be able to get this
   information via REST API.
 * Thanks,
 * Dusan
 *  Plugin Author [Sayan Datta](https://wordpress.org/support/users/infosatech/)
 * (@infosatech)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/#post-11412761)
 * Hi [@dusang](https://wordpress.org/support/users/dusang/)
 * You just need to get the last modified author name of posts. Am I right? or any
   custom post types?
 *  Thread Starter [dusang](https://wordpress.org/support/users/dusang/)
 * (@dusang)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/#post-11412792)
 * Hi Sayan,
 * Yes, you’re right. Even though it’s maybe a custom post type, because of that
   KnowAll theme we’re using. This is REST API URL for posts: [https://COMPANY_URL/wp-json/wp/v2/posts/](https://COMPANY_URL/wp-json/wp/v2/posts/)
   and this is REST API URL for knowledge articles (what we use): [https://COMPANY_URL/wp-json/wp/v2/ht-kb/](https://COMPANY_URL/wp-json/wp/v2/ht-kb/)
 * The schema for ht-kb is almost the same as schema for posts.
 * Thanks,
 * Dusan
 *  Plugin Author [Sayan Datta](https://wordpress.org/support/users/infosatech/)
 * (@infosatech)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/#post-11412805)
 * Hi [@dusang](https://wordpress.org/support/users/dusang/)
 * Add this code to the end of your functions.php file:
 *     ```
       add_action( 'rest_api_init', 'lmt_register_custom_api_field' );
       function lmt_register_custom_api_field() {
           // Add the last modified author name to GET requests for individual posts
           register_rest_field(
               'post',
               'modified_by',
               array(
                   'get_callback'    => 'lmt_cutomize_wp_rest_api_output',
               )
           );
       }
   
       function lmt_cutomize_wp_rest_api_output( $object, $field_name, $request ) {
       	$modified_id = get_post_meta( $object['id'], '_edit_last', true );
       	if( $modified_id ) {
                       $last_user = get_userdata( $modified_id );
   
       	        return $last_user->display_name;
       	}
               return '';
       }
       ```
   
 * And see the results. It will add a field `modified_by` to rest data containing
   Last modified user name if exists.
 * Thanks!
    -  This reply was modified 7 years, 1 month ago by [Sayan Datta](https://wordpress.org/support/users/infosatech/).
      Reason: Use of `register_rest_field()`
 *  Plugin Author [Sayan Datta](https://wordpress.org/support/users/infosatech/)
 * (@infosatech)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/#post-11412956)
 * Hello [@dusang](https://wordpress.org/support/users/dusang/)
 * I have updated this code. Please, check it out.
 * Thanks!
 *  Thread Starter [dusang](https://wordpress.org/support/users/dusang/)
 * (@dusang)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/#post-11412978)
 * Hi Sayan,
 * Thank you once more for your quick answer.
 * If I understand you correctly, you will implement this in the next release. Is
   this correct?
 * I’m not using PHP to get all posts/knowledge bases. I wrote this utility in C#,
   so unfortunately your code snippet won’t help me. What I would need is an example
   REST API request how to query this modified_by field. Something like this: [https://developer.wordpress.org/rest-api/reference/posts/](https://developer.wordpress.org/rest-api/reference/posts/)(
   they are querying all posts there).
 * So is there any REST API call where I can query `modify_by`, please?
 * Thanks
 *  Plugin Author [Sayan Datta](https://wordpress.org/support/users/infosatech/)
 * (@infosatech)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/#post-11412997)
 * Hi [@dusang](https://wordpress.org/support/users/dusang/)
 * Have you tried this?
 *     ```
       add_action( 'rest_api_init', 'lmt_register_custom_api_field' );
       function lmt_register_custom_api_field() {
           // Add the last modified author name to GET requests for individual posts
           register_rest_field(
               'post',
               'modified_by', // you can use anything here like modify_by
               array(
                   'get_callback'    => 'lmt_cutomize_wp_rest_api_output',
               )
           );
       }
   
       function lmt_cutomize_wp_rest_api_output( $object, $field_name, $request ) {
       	$modified_id = get_post_meta( $object['id'], '_edit_last', true );
       	if( $modified_id ) {
                       $last_user = get_userdata( $modified_id );
   
       	        return $last_user->display_name;
       	}
               return '';
       }
       ```
   
 *  Thread Starter [dusang](https://wordpress.org/support/users/dusang/)
 * (@dusang)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/#post-11413020)
 * Hi Sayan,
 * No I haven’t as I’m not using PHP to query REST API.
 * But maybe I don’t understand you… I haven’t installed your plugin yet. So maybe
   this is a code to add to your plugin?
    If this code is for your plugin, will 
   I be able to query `modified_by` by using REST API?
 * Thanks.
 *  Plugin Author [Sayan Datta](https://wordpress.org/support/users/infosatech/)
 * (@infosatech)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/#post-11413070)
 * Hi [@dusang](https://wordpress.org/support/users/dusang/)
 * > WordPress REST API will return only “modified” and “modified_gmt” (both of 
   > them are dates) for posts.
 * As you told before, WordPress does not has any last modified author output in
   REST API. But this code snippet extends the REST API output as it adds the post
   last modified author name to the REST API output.
 * So, you can use that code to extend REST API output of WordPress then you can
   do anything like you want to query it in C#.
 * This feature is not added to the plugin yet. So, I give you that code to add 
   it manually to your functions.php file.
 * For now this plugin just shows post modified author name to the frontend. In 
   future release I may add this Rest Api feature to this plugin.
 * Thanks!
 *  Thread Starter [dusang](https://wordpress.org/support/users/dusang/)
 * (@dusang)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/#post-11413171)
 * Hi Sayan,
 * Thanks for your answer.
    I’m not admin of our WordPress, so I don’t see functions.
   php. I will give your code to our admin, so hopefully he will insert it into 
   the right place.
 * Thank you very much for your help.
 *  Plugin Author [Sayan Datta](https://wordpress.org/support/users/infosatech/)
 * (@infosatech)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/#post-11413200)
 * Hi [@dusang](https://wordpress.org/support/users/dusang/)
 * Ok fine. Can you add plugin to your website? If you can Install Code Snippets
   plugin and create a snippet with my code and activate it. And then check REST
   API output.
 * Thanks!
 *  Thread Starter [dusang](https://wordpress.org/support/users/dusang/)
 * (@dusang)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/#post-11413215)
 * Hi Sayan,
 * No I can’t. I will ask our admin to add that Code Snippets plugin.
 * Thanks.
 *  Plugin Author [Sayan Datta](https://wordpress.org/support/users/infosatech/)
 * (@infosatech)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/#post-11413264)
 * Ok. Please let me know if it doesn’t works.
 * Thanks!
 *  Thread Starter [dusang](https://wordpress.org/support/users/dusang/)
 * (@dusang)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/#post-11421082)
 * Hi Sayan,
 * Thank you very much for your help. I asked our admin to add your code to functions.
   php. Now REST API returns modified_by, but only for the endpoint wp-json/wp/v2/
   posts/. modified_by is empty however, but REST API returns only one record where
   date and modified are the same, so maybe it’s supposed to be empty.
 * Unfortunately for the endpoint wp-json/wp/v2/ht-kb/ there’s no modified_by value
   returned by REST API. I guess I have to contact the author of the KnowAll theme.
 * Once again, thank you very much for your help.
 * Thanks,
 * Dusan

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

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

The topic ‘Access via REST API’ is closed to new replies.

 * ![](https://ps.w.org/wp-last-modified-info/assets/icon-256x256.png?rev=2844152)
 * [WP Last Modified Info](https://wordpress.org/plugins/wp-last-modified-info/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-last-modified-info/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-last-modified-info/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-last-modified-info/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-last-modified-info/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-last-modified-info/reviews/)

 * 16 replies
 * 2 participants
 * Last reply from: [Sayan Datta](https://wordpress.org/support/users/infosatech/)
 * Last activity: [7 years, 1 month ago](https://wordpress.org/support/topic/access-via-rest-api/page/2/#post-11421124)
 * Status: resolved