Add match day to event api rest

This commit is contained in:
MRaouf
2017-11-15 19:50:00 +01:00
parent 866d93b08a
commit 6b7e5230a2
2 changed files with 22 additions and 0 deletions

View File

@@ -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' ); do_action( 'sportspress_register_rest_fields' );
} }

View File

@@ -702,4 +702,10 @@ class SP_Event extends SP_Custom_Post{
public function sort_timeline( $a, $b ) { public function sort_timeline( $a, $b ) {
return $a['time'] - $b['time']; return $a['time'] - $b['time'];
} }
public function day() {
$day = get_post_meta( $this->ID, 'sp_day', true );
if ( '' === $day ) $day = 'empty';
return $day;
}
} }