Add event format to REST API

This commit is contained in:
Brian Miyaji
2021-03-29 12:07:53 +09:00
parent 26902cc811
commit c4cbc5e97c
2 changed files with 39 additions and 18 deletions

View File

@@ -120,21 +120,37 @@ 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',
'schema' => array(
'description' => __( 'Match Day', 'sportspress' ),
'type' => 'string',
'context' => array( 'view', 'edit', 'embed' ),
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
)
);
register_rest_field( 'sp_event',
'format',
array(
'get_callback' => 'SP_REST_API::get_post_data',
'update_callback' => 'SP_REST_API::update_post_meta',
'schema' => array(
'description' => __( 'Format', 'sportspress' ),
'type' => 'string',
'context' => array( 'view', 'edit', 'embed' ),
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
)
);
register_rest_field( 'sp_event',
'day',
array(
'get_callback' => 'SP_REST_API::get_post_data',
'update_callback' => 'SP_REST_API::update_post_meta',
'schema' => array(
'description' => __( 'Match Day', 'sportspress' ),
'type' => 'string',
'context' => array( 'view', 'edit', 'embed' ),
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
)
);
register_rest_field( 'sp_event',
'minutes',

View File

@@ -26,9 +26,14 @@ class SP_Event extends SP_Custom_Post{
return $post_status;
}
public function day() {
$day = get_post_meta( $this->ID, 'sp_day', true );
return $day;
public function format() {
$format = get_post_meta( $this->ID, 'sp_format', true );
return $format;
}
public function day() {
$day = get_post_meta( $this->ID, 'sp_day', true );
return $day;
}
public function minutes() {