diff --git a/includes/api/class-sp-rest-api.php b/includes/api/class-sp-rest-api.php index 76c6220b..7e19b7e2 100644 --- a/includes/api/class-sp-rest-api.php +++ b/includes/api/class-sp-rest-api.php @@ -502,6 +502,22 @@ class SP_REST_API { ), ) ); + + register_rest_field( 'sp_event', + 'day', + array( + 'get_callback' => 'SP_REST_API::get_post_data', + 'update_callback' => 'SP_REST_API::update_post_meta_arrays', + 'schema' => array( + 'description' => __( 'Results', 'sportspress' ), + 'type' => 'array', + 'context' => array( 'view', 'edit' ), + 'arg_options' => array( + 'sanitize_callback' => 'rest_sanitize_request_arg', + ), + ), + ) + ); do_action( 'sportspress_register_rest_fields' ); } diff --git a/includes/class-sp-event.php b/includes/class-sp-event.php index 5ff1c9e1..b256270c 100644 --- a/includes/class-sp-event.php +++ b/includes/class-sp-event.php @@ -702,4 +702,10 @@ class SP_Event extends SP_Custom_Post{ public function sort_timeline( $a, $b ) { return $a['time'] - $b['time']; } + + public function day() { + $day = get_post_meta( $this->ID, 'sp_day', true ); + if ( '' === $day ) $day = 'empty'; + return $day; + } }