How To Use Query Filter In Anywhere Elementor Pro?

Want more control over which posts are displayed in your Elementor layouts?

With Anywhere Elementor Pro’s Post Blocks Advanced widget, you can build dynamic post grids using custom block layouts. And for advanced users, the Query Filter feature unlocks powerful filtering options using WP_Query, allowing you to display posts based on custom fields, taxonomies, authors, and more.

In this guide, you’ll learn how to use custom WP_Query filters with AE Pro to fetch exactly the content you want, no matter how complex your filtering needs are.

Key Takeaways: What You’ll Learn

  • How to connect your custom PHP filters with AE Query Filter
  • What the Post Blocks Advanced widget does in AE Pro
  • How the Query Filter feature works
  • What WP_Query is and how to use it
  • Real-world examples of WP_Query for post filtering
  • How to apply meta queries with custom fields

What Is the Post Blocks Advanced Widget?

The Post Blocks Adv widget in Anywhere Elementor Pro helps you showcase custom post collections beautifully, using your own block layout designs built with Elementor.

It offers 3 skin types:

  • Grid (with options like list, smart grid, checkerboard)
  • Carousel
  • Accordion

You can fully control:

  • Post source (Posts, Pages, CPTs, ACF Relationship/Post Object)
  • Taxonomy filters (categories, tags, custom taxonomies)
  • Author inclusion/exclusion
  • Sorting (by date, title, custom fields)
  • Pagination vs. infinite scroll

You can even display multiple CPTs on the same page, each with unique layouts—just by dragging separate Post Block widgets and tweaking their settings.

Why Use a Query Filter in AE Pro?

While the built-in query options are flexible, sometimes you need more complex filters that go beyond the UI settings, like:

  • Filtering by a custom checkbox field
  • Displaying posts after a certain date
  • Fetching posts based on advanced logic

This is where the Query Filter feature comes in.

AE Pro uses WordPress’s native WP_Query class to fetch posts. The Query Filter lets you hook into that process and modify the query arguments via custom PHP code. Think of it as adding your own logic to WordPress queries—without modifying core files.

Before diving in, let’s quickly understand what WP_Query is and how it works.

What is WP_Query in WordPress?

WP_Query is a popular class available in WordPress. This allows us to fetch data directly from the database. It takes an array of arguments that contains information about which posts are to be fetched.

Below is an example of a simple WP_Query that displays posts by author, using author id:

$query = new WP_Query( array( 'author' => 4 ) );

This simple wp_query code with multiple arguments passed will display published posts ordered by date.

<?php
 
// The Query
$args = array(
    'post_type'      => 'post',
    'post_status'    => 'publish', // Also support: pending, draft, auto-draft, future, private, inherit, trash, any
   'posts_per_page'  => '5', // use -1 for all post
    'order'          => 'DESC', // Also support: ASC
    'orderby'        => 'date',
   ),
);
$the_query = new WP_Query( $args );

How to Use WP_Query With Post Block Advanced Widget Of Anywhere Elementor Pro

Here we will take an example case to show your featured posts using the Post Blocks Advanced widget. Suppose you created a custom field (checkbox) to mark the post as featured.

Now, follow these steps to add your own filter to the Post Block query.

First, find the option “Query Filter” under the “Query” section.

Query filter in Anywhere Elementor Pro
Query filter

Ensure you read the description (warning message) below that field. Add your custom filter name in that field. In this case, we have placed “featured_posts.”

We will need to attach the filter to this function in functions.php of the active child theme.  

See the following code that we have added to fetch only those posts which are marked as featured.

function ae_get_featured_posts($query_args){
   $query_args['meta_key'] = 'is_featured';
   $query_args['meta_value'] = 1;
   return $query_args;
}
 add_filter('featured_posts', 'ae_featured_posts');

If you notice in the above code, we have added a filter to “my_custom_filter.” This function will receive “$query_args” as an argument that will be passed in WP_Query by the Post Blocks Advanced widget. You can modify it and return it from that filter. Here we have added a meta_key related filter to show only those posts that have meta_key “is_featured” set with “meta_value” = 1.

Now, let’s have a look at a more complex example, like using a meta query in the Query filter. See the following code that we have added to fetch only upcoming posts.

function ae_get_upcoming_events($query_args){
  $meta_query[] = array(
        'key' => 'current_date',
        'value' => date('Y-m-d'), //today's date
        'compare' => '>', 
        'type' => 'date'
    );

 $query_args['meta_query'] = $meta_query;

    return $query_args;
}
add_filter('upcoming_events', 'ae_get_upcoming_events');

In the above code, we have added a function, ae_get_upcoming_events, that you need to use in the Query filter of Anywhere Elementor Pro and place this code in functions.php of your active child theme.

Here, we are fetching a list of all upcoming events by comparing dates with today.

FAQs on Query Filter in Anywhere Elementor Pro

What is the Query Filter in Anywhere Elementor Pro?

It’s a feature that allows you to modify the query parameters used in Post Blocks Advanced by hooking into WP_Query with your own custom code.

Do I need coding knowledge to use Query Filter?

Yes. You’ll need a basic understanding of PHP and WordPress’s WP_Query class to write custom filters.

Where do I write the filter code?

You add your PHP filter functions to the functions.php file of your active child theme. Learn how to create a Child Theme in WordPress.

Can I use multiple query filters on the same page?

Yes, you can apply different query filters to different Post Block widgets, each with its own custom logic.

What happens if I enter the wrong filter name?

If the filter name doesn’t match any registered filter function in your code, the widget will fall back to the default query.

Final Thoughts: Unlocking AE Query Filter Power

These were just a few possibilities that we have shown you in the above examples. A query filter has endless possibilities, but you need to have a proper understanding of the query filter and how it works. Click here to learn more about WP_Query. If you have any exceptional cases to use in the query filter, please get in touch with our support team.

To use a customized Query filter in Post Blocks Advanced widget, get Anywhere Elementor Pro.

Leave a Reply

Your email address will not be published. Required fields are marked *