Skip to content

Instantly share code, notes, and snippets.

@abmiller99
Last active September 19, 2023 18:58
Show Gist options
  • Save abmiller99/19e0e8f2d1c32c28c684c530c34817cd to your computer and use it in GitHub Desktop.
Save abmiller99/19e0e8f2d1c32c28c684c530c34817cd to your computer and use it in GitHub Desktop.
Events Loop / Query in Bricks Builder
<?php
/* Add new query type control to query options */
add_filter( 'bricks/setup/control_options', 'bl_setup_query_controls');
function bl_setup_query_controls( $control_options ) {
/* Adding a new option in the dropdown */
$control_options['queryTypes']['upcoming_events_query'] = esc_html__( 'EE4 Upcoming Events Query' );
return $control_options;
};
/* Run new query if option selected */
add_filter( 'bricks/query/run', 'bl_maybe_run_new_query', 10, 2);
function bl_maybe_run_new_query( $results, $query_obj ) {
if ( $query_obj->object_type !== 'upcoming_events_query' ) {
return $results;
}
/* If option is selected, run our new query */
if ( $query_obj->object_type === 'upcoming_events_query' ) {
$results = run_new_query();
}
return $results;
};
/* Setup post data for posts */
add_filter( 'bricks/query/loop_object', 'bl_setup_post_data', 10, 3);
function bl_setup_post_data( $loop_object, $loop_key, $query_obj ) {
if ( $query_obj->object_type !== 'upcoming_events_query' ) {
return $loop_object;
}
global $post;
$post = get_post( $loop_object );
setup_postdata( $post );
return $loop_object;
};
/* Return results from our custom WP Query arguments */
function run_new_query() {
/* Add all of your WP_Query arguments here */
// query params
$posts_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery(
[
'limit' => 8,
'show_expired' => true,
'order_by' => 'start_date',
// 'category_slug' => null,
'sort' => 'DESC',
]
);
return $posts_query->posts;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment