Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter yajuve

    (@yajuve)

    Hi,
    I found how you can add new field in API REST

    First add this function in : sportspress/includes/class-sp-event.php

    
    public function day() {
    		$day = get_post_meta( $this->ID, 'sp_day', true );
    		if ( '' === $day ) $day = 'empty';
    		return $day;
    	}
    

    Then in sportspress/includes/api/class-sp-rest-api.php
    add

    
    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',
    					),
    				),
    			)
    		);
    

    The name of function ‘day’ must be match $attribute (second attribute) in register_rest_field function.

    Best regards

    Roch

    (@rochesterj)

    I’m glad it’s resolved!

    And thanks for sharing your solution!

    Please, let us know if you need anything else.

    Kind Regards,
    -Roch

    Thread Starter yajuve

    (@yajuve)

    Thanks @rochesterj for your answer
    I suggest just to add it in the futur version of SportsPress plugin
    And add search by Matchday in admin interfaces (Matches > Matches)
    like filter by team, league and season
    I think that it’s not very hard to add this feature.
    Thank you in advance

    • This reply was modified 7 years, 6 months ago by yajuve.
    Roch

    (@rochesterj)

    Hi!

    Great ideas!

    Please consider adding it to our ideaboard, that’s where all the ideas can be voted:
    https://tboy.co/ideas

    Kind Regards,
    -Roch

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add match day in events : API REST’ is closed to new replies.