Using ACF Taxonomy field to fill Elementor post widget

I know this might be an obscure question but I could use some thoughts on it. I have a related products taxonomy assigned to product pages, and I need to list the products of the selected taxonomies (done through ACF). It’s being done on the Single Product page within Elementor using the Posts Widget. If I wasn’t using Elementor for this one, it wouldn’t be a problem. It allows custom queries, but I’m not sure what it is looking for in return. Here is the current code:

add_action( ‘elementor/query/my_related_taxonomies’, function ( $query ) {

$related_taxonomies_var = get_field(‘related_taxonomies’);
if ($related_taxonomies_var) {
if (!is_array($related_taxonomies_var)) {
$related_taxonomies_var = array($related_taxonomies_var);
$args = array(
‘post_type’ => ‘products’,
‘tax_query’ => array(
‘taxonomy’ => ‘related-tags’,
‘terms’ => $related_taxonomies_var,

//$query->set(‘post__in’, $args );
print_r($args); });

The above code outputs the following which are the correct taxonomy IDs

Array ( [post_type] => products [tax_query] => Array ( [0] => Array ( [taxonomy] => related-tags [terms] => Array ( [0] => 123 [1] => 124 ) ) ) )

I’m just not sure where to go next with it to get the posts. Has anyone had any experience mixing ACF, Elementor and a custom query?

For reference:

I am using the following code to query a ACF Relationship field correctly:

add_action( ‘elementor/query/my_related_products’, function ( $wp_query, $posts_widget ) {
$selected_products = get_field( ‘related_products’, false, false );
if ( $selected_products ) {
$wp_query->set( ‘post__in’, $selected_products );
else {
} }, 10 ,2 );


Read more here:: Using ACF Taxonomy field to fill Elementor post widget

Leave a Reply

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