Skip to content

Instantly share code, notes, and snippets.

@kevinvess
Last active November 19, 2020 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinvess/6608cec24bc0737a69265fb73a45f939 to your computer and use it in GitHub Desktop.
Save kevinvess/6608cec24bc0737a69265fb73a45f939 to your computer and use it in GitHub Desktop.
UUA Services Widgets Filter – Extend the active upcoming service
<?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