Home › Forums › Calendar Products › Community Events › Any wp-api customization to get day events??
- This topic has 2 replies, 3 voices, and was last updated 8 years, 2 months ago by Support Droid.
-
AuthorPosts
-
February 17, 2016 at 12:31 pm #1074629Carlos JonayParticipant
I´m trying to customize the query to get all day events for my ionic-mobile-app using wp-api, but i only can get incoming events.
My code is something like this:
add_action( 'init', 'tribe_events_post_type_rest_support', 25 ); function tribe_events_post_type_rest_support() { global $wp_post_types; //be sure to set this to the name of your post type! $post_type_name = 'tribe_events'; 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'; } } function add_meta_to_json($data, $post, $request) { $response_data = $data->get_data(); if ( $request['context'] !== 'view' || is_wp_error( $data ) ) { return $data; } if ($response_data['type'] == 'tribe_events') { $response_data['event_meta'] = get_post_meta($response_data['id']); } $thumbnail_id = get_post_thumbnail_id( $post->ID ); $thumbnail = wp_get_attachment_image_src( $thumbnail_id ); $response_data['featured_image_thumbnail_url'] = $thumbnail[0]; $data->data = $response_data; return $data; } add_filter('rest_prepare_tribe_events', 'add_meta_to_json', 10, 3);
As you can see i´m using custom-post-type and getting all the meta info, but i don´t know how to customize the query to get something like this:
$events = tribe_get_events( array( 'eventDisplay' => 'custom', 'start_date' => '2014-10-01 00:01', 'end_date' => '2014-10-31 23:59' ) );
Can anyone help me o give me some advice to get via wp-api all day events (past or incoming) with all the meta-data??
Thx!
- This topic was modified 8 years, 2 months ago by Carlos Jonay. Reason: wrong code example
- This topic was modified 8 years, 2 months ago by Brian.
February 17, 2016 at 4:45 pm #1074704BrianKeymasterHi,
Thanks for using our plugins.
So we do not support the REST API yet, but I will try to help out.
I found this worked for me to get a custom range of events:
/**
* The Events Calendar Basic Custom Query EndPoint Example
*
* @param $data
*
* @return array|null
*
* Get Events from December 31st to January 20th - http://yoursite.org/wp-json/tribe_events/v2/events/custom/2015-12-31/2016-01-20
*
* jQuery.get( "http://events.clientbuild.org/wp-json/tribe_events/v2/events/custom/2015-12-31/2016-01-20", function( response ) {
console.log(response);
} );
*/
function tribe_api_query( $query ) {
$events = tribe_get_events( array(
'eventDisplay' => $query['eventDisplay'],
'start_date' => $query['start_date'],
'end_date' => $query['end_date']
) );
if ( empty( $events ) ) {
return null;
}
return $events;
}
add_action( 'rest_api_init', function () {
register_rest_route( 'tribe_events/v2', '/events/(?P<eventDisplay>[a-z\-]+)/(?P<start_date>[a-z0-9\-]+)/(?P<end_date>[a-z0-9\-]+)', array(
'methods' => 'GET',
'callback' => 'tribe_api_query',
) );
} );Maybe that can work for you to get you started.
I can try to answer some more questions, but I am limited in much support beyond this.
Cheers
March 3, 2016 at 8:35 am #1084855Support DroidKeymasterThis topic has not been active for quite some time and will now be closed.
If you still need assistance please simply open a new topic (linking to this one if necessary)
and one of the team will be only too happy to help. -
AuthorPosts
- The topic ‘Any wp-api customization to get day events??’ is closed to new replies.