• Resolved acp693

    (@acp693)


    Hi, I’m hoping someone might be able to give me a few pointers on this problem, I’ve had no luck asking on the Bricks forum.

    I’ve attached a Pods File/Image/Video field to the standard Page type in WordPress, it’s set to accept multiple files. I’ve uploaded a few images to it.

    I’m editing the page in Bricks builder and have attached a Nestable Slider to the page and I’m trying to populate the slider from the Pods custom field. I’ve enabled the query loop for the first slide in the slider and I’ve attached a Bricks code element to the page and entered the following code

    <?php
    add_filter( 'bricks/posts/query_vars', 'bricks_query_vars_filter', 10, 3 );
    
    function bricks_query_vars_filter( $query_vars, $settings, $element_id ) {
        /* Place your loop element id */
        if ( $element_id === 'mxxzcg' && function_exists( 'pods' ) ) {
            global $post;
    
            // Assuming 'gallery' is the name of the Pods multi-image field
            $pod = pods( 'gallery', $post->ID ); // Replace 'your_pod_name' with the name of your Pods
    
            if ( ! empty( $pod ) ) {
                // Retrieve the multi-image field data as an array of image IDs
                $gallery_ids = $pod->field( 'gallery', true );
    
                if ( empty( $gallery_ids ) ) {
                    /* Make sure that no posts are returned when
                     * there are no images in the gallery
                     */
                    $query_vars['post__in'] = [0];
                    return $query_vars;
                }
    
                $query_vars['post__in'] = $gallery_ids;
            }
        }
    
        return $query_vars;
    }
    ?>
    

    I have the following query loop settings under content:
    Type: posts
    Post Type: Media
    Child of: {post_id}

    And for the Background image, I also have {post_id} set.

    The slider is just returning all images attached to the page rather than just the images uploaded to the Pods custom field.

    Any help would be great.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Paul Clark

    (@pdclark)

    // Assuming 'gallery' is the name of the Pods multi-image field
     $pod = pods( 'gallery', $post->ID ); // Replace 'your_pod_name' with the name of your Pods

    gallery above should be post —?this argument is the post type, not the field name.

    // Retrieve the multi-image field data as an array of image IDs
    $gallery_ids = $pod->field( 'gallery', true );

    The second argument above should be false rather than true if it is a multi-image field, as there are multiple images.

    Thread Starter acp693

    (@acp693)

    Hi Paul, many thanks for your help. I fixed both of the points you mentioned, but it still doesn’t work, the query simply retrieves everything attached to the page whether it’s in the custom field or not. It seems this has been made to work with other custom field plugins, but I’ve not seen anyone else yet try it with pods. Would you have any other ideas what might be wrong?

    Thanks again

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using the pods Multi-image field to populate a nestable slider in Bricks builder’ is closed to new replies.