epl_elementor_loop_query_args: change the query of a Loop Grid using an EPL template
Description #
Filters the query arguments of an Elementor Pro Loop Grid whose Loop Item template is built with EPL widgets. Use it to change which listings (or staff) every such Loop Grid shows, without setting a Query ID on each one.
EPL treats a template as a listing template when it's an EPL Single Listing or EPL Listing Card template, or contains EPL listing widgets (property widgets or the Agents widget), and as a staff template when it contains EPL agent widgets. Before the filter, EPL sets the post type when the Loop Grid left it empty or set it to post (the listing type from the archive template's conditions, or all EPL listing types; directory for staff) and adds epl_elementor_loop and epl_elementor_context to the arguments.
It runs on Elementor Pro's elementor/query/query_args filter (priority 20). Elementor Pro doesn't run that filter for a Loop Grid whose source is Current Query, so this filter doesn't either.
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_filter( 'epl_elementor_loop_query_args', 'my_function', 10, 3 );
Parameters #
$query_args (array)
WP_Query arguments. epl_elementor_context is listing or staff.
$widget (\Elementor\Widget_Base)
The Loop Grid widget.
$template_id (int)
The ID of the Loop Item template the Loop Grid uses.
Examples #
Leave sold and leased listings out of every Loop Grid that uses an EPL listing template:
function my_epl_loop_hide_sold( $query_args, $widget, $template_id ) {
if ( 'listing' !== $query_args['epl_elementor_context'] ) {
return $query_args;
}
$query_args['meta_query'] = isset( $query_args['meta_query'] ) ? (array) $query_args['meta_query'] : array();
$query_args['meta_query'][] = array(
'key' => 'property_status',
'value' => array( 'sold', 'leased' ),
'compare' => 'NOT IN',
);
return $query_args;
}
add_filter( 'epl_elementor_loop_query_args', 'my_epl_loop_hide_sold', 10, 3 );
Source #
lib/page-builders/elementor/class-epl-elementor.php, in EPL_Elementor::elementor_loop_query_args(). Since 3.6.