Skip to content

Instantly share code, notes, and snippets.

@carlosonweb
Last active January 2, 2019 09:06
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 carlosonweb/7929b20a8c13ea806b2b785ab92ec4b1 to your computer and use it in GitHub Desktop.
Save carlosonweb/7929b20a8c13ea806b2b785ab92ec4b1 to your computer and use it in GitHub Desktop.
TEC vs Post "fl_builder_loop_query_args" Filter Hook
<?php
/**
*
* This works on regular post type.
*
*/
add_filter( 'fl_builder_loop_query_args', function( $query_args ){
$today = date( 'Y-m-d H:i:s', time() );
if ( is_page( 'display-past-events' ) && ( 'bbtest-posts-past-events' === $query_args[ 'settings' ]->id ) ) {
// Meta Key comes from ACF Plugin
// --------------------------------
// $query_args[ 'meta_key' ] = 'eventenddate';
// $query_args[ 'meta_value' ] = $today;
// $query_args[ 'meta_compare' ] = '<';
$query_args[ 'meta_query'] = array(
array(
'key' => 'eventenddate',
'value' => $today,
'type' => 'date',
'compare' => '<',
),
);
}
return $query_args;
} );
/**
*
* This doesn't work on the TEC (tribe_events) Post type.
* Instead, the result is always: "Sorry, we couldn't find any posts. Please try a different search."
*
*/
add_filter( 'fl_builder_loop_query_args', function( $query_args ){
$today = date( 'Y-m-d H:i:s', time() );
if ( is_page( 'display-past-events' ) && ( 'bbtest-tec-past-events' === $query_args[ 'settings' ]->id ) ) {
// $query_args[ 'meta_key' ] = '_EventEndDate';
// $query_args[ 'meta_value' ] = $today;
// $query_args[ 'meta_compare' ] = '<';
$query_args[ 'meta_query'] = array(
array(
'key' => '_EventEndDate',
'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