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

Bricks Version: 1.6.2
*Browser chrome

Hi guys
It will be so helpful if nestable slider support media query like what carousel does

its a quite useful option because we will be able to use Nestable slider to output gallery field (acf/ JetEngine) in SINGLE template


It does. Just choose Posts with the post type Media.

See Query Loop – Bricks Academy.

Thank you for your reply, I meant gallery field added by plugins like acf/ JetEngine

Assume that you have added a galley field to the POSTS and in your single template you want to show the gallery field through Nestable slider

At the moment its not possible

Ok. Got it.

You can create your own query for this scenario. In my example below I added an ACF gallery field (called gallery) to the regular post post type.

add_filter( 'bricks/setup/control_options', function( $control_options ) {
    $control_options['queryTypes']['gallery'] = esc_html__( 'Galerie', 'as' );
    return $control_options;
} );

add_filter( 'bricks/query/run', function( $results, $query_obj ) {
    switch ( $query_obj->object_type ) {
        case 'gallery':
            $images = get_field( 'gallery' );
            if ( ! empty( $images ) ) {
                $results = $images;
    return $results;
}, 10, 2 );

add_filter( 'bricks/query/loop_object', function( $loop_object, $loop_key, $query_obj ) {
    switch ( $query_obj->object_type ) {
        case 'gallery':
            global $post;
            $post = get_post( $loop_object['ID'] );
            setup_postdata( $post );
    return $post;
}, 10, 3 );

CleanShot 2023-02-13 at 09.41.36@2x



Thank you
In my case i should replace custom field name (gallery), yes?
Whats Galerie? Should i change it too?

By the way i like to ask @timmse to make it compatible so it will be easier, because i don’t know about coding

I thought about it again and there is an even easier way without a completely custom query. Just use the bricks/posts/query_vars hook.

add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {
    if ( $element_id === 'cghjvv' && function_exists( 'get_field' ) ) {
        $gallery = get_field( 'gallery' );
        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;
        /* Get the first gallery item to automatically determine
         * the ACF gallery field's return format
        $test_item = current( $gallery );
        if ( is_array( $test_item ) ) {
            // Get image IDs from image arrays
            $gallery = array_map( function( $image_array ) {
                return $image_array['ID'];
            }, $gallery );
        } else if ( is_string( $test_item ) ) {
            // Try to get image IDs from image urls
            $gallery = array_map( function( $image_url ) {
                return attachment_url_to_postid( $image_url );
            }, $gallery );
        $query_vars['post__in'] = $gallery;
    return $query_vars;
}, 10, 3 );

Just change the element ID in my snippet (cghjvv) to the ID of your query loop element’s ID. And change gallery to the name of your custom gallery field.

And these are the query loop settings.

Again: This code is using ACF.


Hey Mehdi,
This is not a bug report, but a feature request :wink: I will move the thread.

Official feature requests are still to be submitted via the Idea Board: Ideas – Bricks
This way we can see how many users have a need for this feature. Until then, I think Andre’s code is very easy to use.

You don’t have to, that’s what you have @aslotta for :sweat_smile: :+1:

Best regards,


Thank you for your reply, and also thanks to @aslotta
I thought its a quite useful feature and its easy for you guys to implement :sweat_smile:

Also almost in every website with a cpt (real estate, services, portfolio and etc) we need a gallery
And Nestable slider would be a great choice to render the results


Agree with this totally

Awesome help thanks aslotta. If we wanted to use this query across a few different elements, is there a better/cleaner way than targeting the element ID(s)?

Also, are you choosing the post type that contains the ACF when you pick ‘Medien’ please? When I do that, it just loops through the posts in that post type instead :slight_smile:

1 Like