epl_elementor_loop_query: change an Elementor Pro query with the epl_listings Query ID
Description #
Lets you change the listings query of an Elementor Pro widget whose Query ID is epl_listings (for example a Loop Grid). Type epl_listings into the widget's Query ID field, then hook this action to adjust the query.
Before the action runs, EPL sets the query's post type to all EPL listing types when the widget left it empty or set it to post, and marks the query with epl_elementor_loop = true. It runs while WordPress prepares the query (Elementor Pro fires elementor/query/epl_listings on pre_get_posts), so change it with $query->set(). Needs Elementor Pro.
Part of the Elementor integration, which is in beta. See Elementor widgets and templates (beta) for how the widgets and templates fit together.
Usage #
add_action( 'epl_elementor_loop_query', 'my_function', 10, 2 );
Parameters #
$query (WP_Query)
The query about to run. Change it with $query->set().
$widget (\Elementor\Widget_Base)
The Elementor widget that owns the query. Use $widget->get_id() to target one widget.
Examples #
Only show current listings that are marked as featured:
function my_epl_featured_loop( $query, $widget ) {
$meta_query = $query->get( 'meta_query' );
$meta_query = is_array( $meta_query ) ? $meta_query : array();
$meta_query[] = array(
'key' => 'property_status',
'value' => 'current',
);
$meta_query[] = array(
'key' => 'property_featured',
'value' => 'yes',
);
$query->set( 'meta_query', $meta_query );
}
add_action( 'epl_elementor_loop_query', 'my_epl_featured_loop', 10, 2 );
Source #
lib/page-builders/elementor/class-epl-elementor.php, in EPL_Elementor::elementor_listings_query(), hooked to elementor/query/epl_listings. Since 3.6.