Introduction
If you’ve ever felt limited by the default Elementor Post or Loop Grid filters, then an Elementor custom query is precisely what you need. In this tutorial, you’ll learn how to:
- Add a Custom Query ID in Elementor Pro
- Hook into Elementor using elementor/query/{your_query_id}
- Modify the underlying WP_Query with filters, ordering, metadata, status, and more
- Apply the custom query in the Elementor UI
Perfect for developers looking to filter posts by category, meta values, or custom post types with complete control.
Companion Video
Step 1: Assign a Query ID in Elementor
- In Elementor Pro, edit a Posts or Loop Grid widget.
- Navigate to Content → Query → Query ID.
- Enter a unique ID, for example:
my_custom_filter.- That creates the hook name:
elementor/query/my_custom_filter
- That creates the hook name:
Step 2: Add Your Custom Query in functions.php
In your theme (or child theme) functions.php, add:
add_action('elementor/query/my_custom_filter', function( \WP_Query $query ) {
// your modifications go here
});Replace my_custom_filter with the ID you set in Elementor.
Step 3: Customize the Query
Here are some practical Elementor custom query examples:
Show Specific Post Types
$query->set('post_type', ['post','your_cpt']);Filter by Meta Key (ACF or Custom Field)
$query->set('meta_key', 'sorting');
$query->set('orderby', 'meta_value');
$query->set('order', 'ASC');Order by Popularity (Comment Count)
$query->set('orderby', 'comment_count');
$query->set('order', 'DESC');Include Specific Post Statuses
$query->set('post_status', ['publish', 'future', 'draft']);Exclude Certain Posts by ID
$query->set('post__not_in', [7, 11]);Combine Filters
add_action('elementor/query/my_custom_filter', function( \WP_Query $query ) {
$query->set('post_type', ['post',' portfolio']);
$query->set('meta_key', 'project_type');
$query->set('meta_query', [
['key'=>'project_type','value'=>['design','development'],'compare'=>'IN']
]);
$query->set('orderby','comment_count');
$query->set('order','DESC');
});Step 4: Using the Query in Elementor
- Make sure the Query ID in the widget matches your hook.
- Update or refresh the Elementor editor to see your filter applied.
- Preview to confirm results.
Additional Use Cases for an Elementor custom query
- Filter future events by post status or date.
- Display custom post types (e.g., events, products, portfolio items)
- Sort by ACF fields like ratings, dates, or custom criteria
Pro Tips
- Use descriptive Query ID names (e.g., filter_events_cpt) to avoid conflicts or future confusion.
- Test hooks with simple filters first to make sure you’re on the right track.
- Leverage meta_query, tax_query, and date_query for advanced filtering. (See below.)
- Make child-theme or site-specific plugin changes to keep your code portable.
Advanced Filtering with meta_query, tax_query, and date_query
Elementor custom query hooks give you full access to the underlying WP_Query object, allowing you to filter content using meta fields, taxonomies, and dates, just like in advanced WordPress development.
These powerful parameters allow you to target particular subsets of content, perfect for showcasing featured posts, events, products, or custom post types.
meta_query – Filter by Custom Fields (e.g. ACF)
Use meta_query to filter posts by custom fields (like ratings, prices, or flags):
$query->set('meta_query', [
[
'key' => 'rating',
'value' => 4,
'compare' => '>=',
'type' => 'NUMERIC'
]
]);Use case examples:
- Show only posts with a minimum ACF rating
- Display items on sale (sale_price > 0)
- Filter by custom flags like featured = true
WordPress meta_query reference
tax_query – Filter by Categories, Tags, or Custom Taxonomies
Use tax_query to filter posts by taxonomy terms, including custom ones like genres, event types, or regions.
$query->set('tax_query', [
[
'taxonomy' => 'project_type',
'field' => 'slug',
'terms' => ['design', 'development'],
'operator' => 'IN',
]
]);Use case examples:
- Show only posts from specific categories or tags
- Display portfolio items by type (project_type)
- Exclude posts with a given taxonomy term
date_query – Filter by Dates (Upcoming Events, Archives, etc.)
Use date_query to filter by post date, including ranges, years, months, or even days of the week.
$query->set('date_query', [
[
'after' => 'today',
'inclusive' => true
]
]);Use case examples:
- Show only future-dated posts (like scheduled events)
- Display posts from this month
- Create archive-style queries
WordPress date_query reference
Combining Multiple Query Types
You can combine all three types to build highly customized filters:
$query->set('post_type', 'event');
$query->set('meta_query', [
[
'key' => 'event_price',
'value' => 0,
'compare' => '>',
'type' => 'NUMERIC'
]
]);
$query->set('tax_query', [
[
'taxonomy' => 'event_type',
'field' => 'slug',
'terms' => ['concert', 'festival'],
]
]);
$query->set('date_query', [
[
'after' => 'today'
]
]);Conclusion
Using an Elementor Custom Query Filter lets you transform the Posts or Loop Grid widget into a flexible, fully programmable display block. By combining Query IDs with elementor/query/* hooks, you control precisely which posts to show—and in what order.



