Support

Account

Home Forums General Issues Elementor Custom Query Based on ACF Data

Helping

Elementor Custom Query Based on ACF Data

  • I’m using the Elementor post widget and trying to apply a Query that will filter based on an Advanced Custom Field.

    My ideal workflow:

    1. Check the category of the current post the widget is on
    2. Return the pages that have that category set to the ACF I made called “pack-slug”

    add_action( 'elementor/query/find_corresponding_packs', function( $query ) {
        
        $trailer_categories = get_the_category(); //get the current post category
        
        $pack_slug = get_field('pack_slug'); //get the ACF (I think this isn't correct)
    
        $query->set( 'post_type',  'page' ); //limit to pages
    
        //iterate through the categories
        foreach($trailer_categories as $cat){
            $query->set( $pack_slug,  $cat->slug );
    
        }
    });

    Any ideas why this isn’t working?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.