David Valentine commited on 2026-05-01 05:10:07
Showing 1 changed files, with 36 additions and 0 deletions.
| ... | ... |
@@ -37,6 +37,10 @@ if ( ! class_exists( 'SP_REST_API' ) ) : |
| 37 | 37 |
// Add filters to query scheduled events |
| 38 | 38 |
add_filter( 'rest_sp_event_query', array( $this, 'event_query' ) ); |
| 39 | 39 |
add_filter( 'rest_query_vars', array( $this, 'query_vars' ) ); |
| 40 |
+ |
|
| 41 |
+ // Add filters to query players with teams filter |
|
| 42 |
+ add_filter( 'rest_sp_player_collection_params', array( $this, 'player_vars' ) ); |
|
| 43 |
+ add_filter( 'rest_sp_player_query', array( $this, 'player_query' ), 10, 2 ); |
|
| 40 | 44 |
} |
| 41 | 45 |
|
| 42 | 46 |
/** |
| ... | ... |
@@ -917,6 +921,38 @@ if ( ! class_exists( 'SP_REST_API' ) ) : |
| 917 | 921 |
$vars[] = 'post_status'; |
| 918 | 922 |
return $vars; |
| 919 | 923 |
} |
| 924 |
+ |
|
| 925 |
+ /** |
|
| 926 |
+ * Add query vars for players. |
|
| 927 |
+ */ |
|
| 928 |
+ public static function player_vars( $vars ) {
|
|
| 929 |
+ $vars['teams'] = array( |
|
| 930 |
+ 'description' => esc_attr__( 'Teams', 'sportspress' ), |
|
| 931 |
+ 'type' => 'array', |
|
| 932 |
+ 'items' => array( |
|
| 933 |
+ 'type' => 'integer', |
|
| 934 |
+ ), |
|
| 935 |
+ ); |
|
| 936 |
+ |
|
| 937 |
+ return $vars; |
|
| 938 |
+ } |
|
| 939 |
+ |
|
| 940 |
+ /** |
|
| 941 |
+ * Filter players query. |
|
| 942 |
+ */ |
|
| 943 |
+ public static function player_query( $args, $request ) {
|
|
| 944 |
+ $teams = $request->get_param( 'teams' ); |
|
| 945 |
+ |
|
| 946 |
+ if ( ! empty( $teams ) ) {
|
|
| 947 |
+ $args['meta_query'][] = array( |
|
| 948 |
+ 'key' => 'sp_team', |
|
| 949 |
+ 'value' => array_map( 'intval', (array) $teams ), |
|
| 950 |
+ 'compare' => 'IN', |
|
| 951 |
+ ); |
|
| 952 |
+ } |
|
| 953 |
+ |
|
| 954 |
+ return $args; |
|
| 955 |
+ } |
|
| 920 | 956 |
} |
| 921 | 957 |
|
| 922 | 958 |
endif; |
| 923 | 959 |