add custom event parse request

For some reason it doesn't run through sportspress' query parser. i can't figure out why, but this is a way around it.
This commit is contained in:
2024-05-20 16:40:08 -05:00
parent 3ecb7ea937
commit b4b31f8123

View File

@@ -74,3 +74,16 @@ function custom_event_rewrite_flush() {
}
register_activation_hook(__FILE__, 'custom_event_rewrite_flush');
register_deactivation_hook(__FILE__, 'flush_rewrite_rules');
// Modify the query to handle custom permalinks and include future posts
function custom_event_parse_request($query) {
$post_type = sp_array_value( $query->query, 'post_type', null );
if (isset($query->query_vars['post_type']) && $query->query_vars['post_type'] === 'sp_event') {
if (isset($query->query_vars['p'])) {
$query->set('post_type', 'sp_event');
$query->set('p', $query->query_vars['p']);
$query->set('post_status', array('publish', 'future'));
}
}
}
add_action('pre_get_posts', 'custom_event_parse_request');