Skip to content

Instantly share code, notes, and snippets.

@carlosonweb
Last active February 14, 2020 18:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save carlosonweb/a25abcc023f462521330cda36e14debe to your computer and use it in GitHub Desktop.
Save carlosonweb/a25abcc023f462521330cda36e14debe to your computer and use it in GitHub Desktop.
Beaver Builder Filter Hook: fl_builder_loop_query_args To Filter by Meta Keys
/**
* Add this to the child theme's functions.php file.
*/
add_filter( 'fl_builder_loop_query_args', function( $query_args ){
$today = date( 'd.m.Y', time() );
// Past ( today > start_date )
if ( 'PAST_POST_MODULE_ID_HERE' == $query_args[ 'settings' ]->id ) {
$query_args[ 'meta_query' ] = array(
'key' => 'end_date',
'value' => $today,
'type' => 'date',
'compare' => '<'
);
}
// Future ( today < start_date )
if ( 'FUTURE_POST_MODULE_ID_HERE' == $query_args[ 'settings' ]->id ) {
$query_args[ 'meta_query' ] = array(
'key' => 'start_date',
'value' => $today,
'type' => 'date',
'compare' => '>'
);
}
// Current ( start_date <= today <= end_date )
if ( 'CURRENT_POST_MODULE_ID_HERE' == $query_args[ 'settings' ]->id ) {
$query_args[ 'meta_query' ] = array(
'relation' => 'AND',
array(
'key' => 'start_date',
'value' => $today,
'type' => 'date',
'compare'=> '>='
),
array(
'key' => 'end_date',
'value' => $today,
'type' => 'date',
'compare' => '<='
)
)
}
return $query_args;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment