Title: Rest API
Last modified: March 30, 2019

---

# Rest API

 *  Resolved [colinaut](https://wordpress.org/support/users/colinaut/)
 * (@colinaut)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/rest-api-53/)
 * So I’m trying to get the events list to be accessed via REST. I know the plugin
   basically just makes a “event” custom post type so the following code should 
   work to register it:
 *     ```
       add_filter( 'register_post_type_args', 'my_post_type_args', 10, 2 );
   
       function my_post_type_args( $args, $post_type ) {
   
           if ( 'event' === $post_type ) {
               $args['show_in_rest'] = true;
           }
   
           return $args;
       }
       ```
   
 * When I do this call up the schema event shows up as a possible query so the “
   show_in_rest” is registering the event post_type. However when I make a GET call
   to it all I get is an empty array. Anyone know what I need to do to get a list
   of events?

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [snorklebum](https://wordpress.org/support/users/snorklebum/)
 * (@snorklebum)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/rest-api-53/#post-11397484)
 * Hi Colinaut,
 * Just been looking at this myself today and added the following to functions.php
 *     ```
       add_filter( 'register_post_type_args', 'my_post_type_args', 10, 2 );
   
       function my_post_type_args( $args, $post_type ) {
   
           if ( 'event' === $post_type ) {
               $args['show_in_rest'] = true;
   
               // Optionally customize the rest_base or rest_controller_class
               $args['rest_base']             = 'events';
               $args['rest_controller_class'] = 'WP_REST_Posts_Controller';
           }
   
           return $args;
       }
       ```
   
 * Now I can see my events listed within wp-json/wp/v2/events and query specific
   events. I’ve not managed to work out how to make custom meta appear yet.
 *  [Stonehenge Creations](https://wordpress.org/support/users/duisterdenhaag/)
 * (@duisterdenhaag)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/rest-api-53/#post-11397528)
 * Guys,
    What are you trying to accomplish exactly? The event custom post type 
   is not the actual EM_Event Object, so the default post query will probably not
   give the desired results.
 *  [snorklebum](https://wordpress.org/support/users/snorklebum/)
 * (@snorklebum)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/rest-api-53/#post-11397541)
 * The code above allows the events to be listed via the wp-json api which in turn
   lets me use the data in an app I’m playing with. My only issue at the moment 
   is getting the custom meta relating to these events exposed using the same method.
 *  [Stonehenge Creations](https://wordpress.org/support/users/duisterdenhaag/)
 * (@duisterdenhaag)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/rest-api-53/#post-11397555)
 * > My only issue at the moment is getting the custom meta relating to these events
   > exposed using the same method.
 * Again: what meta? Because I think, that is exactly what I meant. 😉
 * The custom post type only contains these meta keys by default. All other info
   is contained in the EM_Event Object.
 *     ```
       (
           [0] => _thumbnail_id
           [1] => _custom_booking_form
           [2] => _event_timezone
           [3] => _event_start_time
           [4] => _event_end_time
           [5] => _event_start
           [6] => _event_end
           [7] => _event_start_date
           [8] => _event_end_date
           [9] => _event_rsvp
           [10] => _event_rsvp_date
           [11] => _event_rsvp_time
           [12] => _event_rsvp_spaces
           [13] => _event_spaces
           [14] => _location_id
           [15] => _event_start_local
           [16] => _event_end_local
           [17] => _recurrence_id
           [18] => _event_id
       )
       ```
   
    -  This reply was modified 7 years, 1 month ago by [Stonehenge Creations](https://wordpress.org/support/users/duisterdenhaag/).
 *  [snorklebum](https://wordpress.org/support/users/snorklebum/)
 * (@snorklebum)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/rest-api-53/#post-11397589)
 * The default information exposed via the REST api is what would be standard on
   a post, none of the fields listed above will display unless show_in_rest is set
   to true. Personally I’m only interested in exposing a few of these and custom
   attributes which area also in the postmeta table, I’ve tried adding variations
   of the following to functions.php
 *     ```
       // The object type. For custom post types, this is 'post';
       // for custom comment types, this is 'comment'. For user meta,
       // this is 'user'.
       $object_type = 'post';
       $args1 = array( // Validate and sanitize the meta value.
           // Note: currently (4.7) one of 'string', 'boolean', 'integer',
           // 'number' must be used as 'type'. The default is 'string'.
           'type'         => 'string',
           // Shown in the schema for the meta key.
           'description'  => 'A meta key associated with a string meta value.',
           // Return a single value of the type.
           'single'       => true,
           // Show in the WP REST API response. Default: false.
           'show_in_rest' => true
       );
       register_meta( $object_type, '_event_start_local', $args1 );
       ```
   
 * I’m probably doing things completely wrong 🙂
 *  [Stonehenge Creations](https://wordpress.org/support/users/duisterdenhaag/)
 * (@duisterdenhaag)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/rest-api-53/#post-11397636)
 * I will stop following this topic now. Good luck.
 *  [snorklebum](https://wordpress.org/support/users/snorklebum/)
 * (@snorklebum)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/rest-api-53/#post-11409551)
 * [@colinaut](https://wordpress.org/support/users/colinaut/) I raised a query on
   the main [wordpress support](https://wordpress.org/support/topic/adding-postmeta-to-wp-json-custom-post-type/)
   and from their testing the code above works, I’ve not had the same success.
 * If you do get a chance to test could you let me know if you have any luck?
 * Thanks

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Rest API’ is closed to new replies.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=3550347)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

## Tags

 * [rest](https://wordpress.org/support/topic-tag/rest/)

 * 7 replies
 * 3 participants
 * Last reply from: [snorklebum](https://wordpress.org/support/users/snorklebum/)
 * Last activity: [7 years, 1 month ago](https://wordpress.org/support/topic/rest-api-53/#post-11409551)
 * Status: resolved