Created
January 29, 2023 18:49
-
-
Save kadimi/daa099a5c9fc2ac15a8a185464400b5c to your computer and use it in GitHub Desktop.
SportsPress - Customize past events list columns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Customize past events list columns. | |
*/ | |
add_action( 'init', function() { | |
/** | |
* Desired columns. | |
* | |
* @var array | |
*/ | |
$columns = [ | |
'event', | |
'time', | |
'results', | |
'league', | |
'season', | |
]; | |
/** | |
* Only run once. | |
*/ | |
static $overridden = false; | |
/** | |
* Capture. | |
*/ | |
add_action( 'sportspress_before_template', function( $template_name, $_, $__, $args ) use ( $overridden ) { | |
if ( $overridden | |
|| $template_name !== 'event-list.php' | |
|| $args[ 'title' ] !== __( 'Past Meetings', 'sportspress' ) | |
) { | |
return; | |
} | |
ob_start(); | |
}, 10, 4 ); | |
/** | |
* Override. | |
*/ | |
add_action( 'sportspress_after_template', function( $template_name, $_, $__, $args ) use ( &$overridden ) { | |
if ( $overridden | |
|| $template_name !== 'event-list.php' | |
|| $args[ 'title' ] !== __( 'Past Meetings', 'sportspress' ) | |
) { | |
return; | |
} | |
$overridden = true; | |
ob_get_clean(); | |
sp_get_template( 'event-list.php', array( | |
'title' => __( 'Past Meetings', 'sportspress' ), | |
'show_title' => true, | |
'teams_past' => get_post_meta( get_the_ID(), 'sp_team' ), | |
'date_before' => get_post_time( 'Y-m-d', true ), | |
'title_format' => 'homeaway', | |
'time_format' => 'separate', | |
'columns' => $columns, | |
'order' => 'DESC', | |
'hide_if_empty' => true, | |
) ); | |
}, 10, 4 ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment