Created
April 15, 2023 00:16
-
-
Save kadimi/7b41c129cec3c1be80255e57b47daa42 to your computer and use it in GitHub Desktop.
Add links to tournaments on events
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 | |
function sp_get_event_tournaments($event_id) | |
{ | |
return get_posts([ | |
'post_type' => 'sp_tournament', | |
'posts_per_page' => -1, | |
'meta_query' => [ | |
[ | |
'key' => 'sp_event', | |
'value' => $event_id, | |
] | |
] | |
]); | |
} | |
/** | |
* Add a player list on the fly to the current team. | |
*/ | |
add_action( | |
'init', | |
function () { | |
add_filter( | |
'the_content', | |
function ($content) { | |
$additional_content = ''; | |
$object = get_queried_object(); | |
/** | |
* Exit if this is not a SportsPress event. | |
*/ | |
if ('sp_event' !== $object->post_type) { | |
return $content; | |
} | |
$tournaments = sp_get_event_tournaments($object->ID); | |
if ($tournaments) { | |
ob_start(); | |
?> | |
<h3>Tournaments</h3> | |
<ul> | |
<?php foreach ($tournaments as $tournament) : ?> | |
<li><a href="<?php the_permalink(); ?>"><?php echo get_the_title($tournament); ?></a></li> | |
<?php endforeach; ?> | |
</ul> | |
<?php | |
$additional_content = ob_get_clean(); | |
} | |
/** | |
* Done | |
*/ | |
return $content . $additional_content; | |
}, | |
10 | |
); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment