Media query and Nestable slider (acf/ JetEngine gallery field)

I have tweaked @aslotta code a bit. It was try an error but this is working.

add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {
   /* Place your loop element id */
    if ( $element_id === 'cewxop' ) {
        global $post;
        $gallery = get_post_meta( $post->ID, 'gallery', true ); // JetEngine media meta field (array with ID)
        if ( empty( $gallery ) ) {
            /* Make sure that no posts are returned when
             * there are no images in the gallery
             */
            $query_vars['post__in'] = [0];
            return $query_vars;
        }

        // Convert the gallery IDs string into an array
        $gallery_ids = array_map( 'intval', explode( ',', $gallery ) );

        $query_vars['post__in'] = $gallery_ids;
    }
    
    return $query_vars;
}, 10, 3 );

Hope it helps someone later on :slight_smile: .

5 Likes