Overview
This article will use a query hook to filter posts using Query ID on Dynamic Content for Elementor.
Background
Elementor originally created the Query ID filter for its Posts widget, and we’ve integrated the same functionality into several of our widgets. You can use a hook to filter a query. Using the following example code, you can achieve this:
Example Code
function my_query_filter( $query ) {
$query->set( 'post_type', [ 'custom-post-type1', 'custom-post-type2' ] );
}
add_action( 'dynamicooo/query/{$query_id}', 'my_query_filter' );
Usage
To use this hook feature, you will need to use the hook dynamicooo/query/{query_id}
.
You can use this hook on the following widgets: Dynamic Posts, Dynamic Products, Dynamic Products On Sale, Products in the Cart, Product Upsells, Product Cross-Sells, ACF Relationship, Favorites, Woo Wishlist, Sticky Posts, Search Results, Posts by the Current User.
However, you cannot use the hook that Elementor uses: elementor/query/{$query_id}
.