Last active
November 19, 2020 21:42
-
-
Save kevinvess/6608cec24bc0737a69265fb73a45f939 to your computer and use it in GitHub Desktop.
UUA Services Widgets Filter – Extend the active upcoming service
This file contains 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 | |
/** | |
* Filter the UUA Services 'Upcoming Service' Query. | |
* | |
* Extend the time by two hours before switching to the next service. | |
* | |
* @param array $query_args An array of query arguments. | |
* @return array | |
*/ | |
function extend_upcoming_service_display( $query_args ) { | |
if ( isset( $query_args['meta_query'] ) ) { | |
// get the index of the meta_key value | |
$index = array_search( $query_args['meta_key'], array_column( $query_args['meta_query'], 'key' ), true ); | |
if ( isset( $query_args['meta_query'][$index]['value'] ) ) { | |
// set the additional time in seconds | |
$extension = ( 2 * HOUR_IN_SECONDS ); | |
// adjust the query to be in the past to keep the "active" service for longer | |
$query_args['meta_query'][$index]['value'] = current_time('timestamp') - $extension; | |
} | |
} | |
return $query_args; | |
} | |
add_filter( 'uua_widget_featured_service_query_args', 'extend_upcoming_service_display' ); | |
add_filter( 'uua_widget_upcoming_services_query_args', 'extend_upcoming_service_display' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment