Skip to content

Instantly share code, notes, and snippets.

@mafsdisseny
Created February 20, 2023 14:40
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 mafsdisseny/159593d063d9db9dffc04ed0effa5388 to your computer and use it in GitHub Desktop.
Save mafsdisseny/159593d063d9db9dffc04ed0effa5388 to your computer and use it in GitHub Desktop.
GeneratePress & GenerateBlocks > Query loop block ||| Función para filtrar la salida del query loop cuando no se pueden editar las opciones desde su propia UI
// SOURCE: https://generatepress.com/forums/topic/use-query-loop-to-display-the-events-calendar-events-on-home-page/
//
// Mostrar solo eventos futuros
// GeneratePress, GenerateBlocks, ACF
// Hay que añadir clase personalizada al grid del query loop para discriminar sobre el resto de query loops
// En este caso usamos fecha en formato Ymd porque es como guarda ACF las fechas de date picker en la DB
function mafs_agenda_show_future_events( $query_args, $attributes ) {
if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'mostrar-agenda-futura' ) !== false ) {
$custom_args = array(
'meta_key' => 'data_agenda',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'data_agenda',
'value' => date('Ymd'),
'type' => 'DATE',
'compare' => '>=',
),
),
);
} else {
return $query_args;
}
return array_merge( $query_args, $custom_args );
}
add_filter( 'generateblocks_query_loop_args', 'mafs_agenda_show_future_events', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment