NO BUG: Dynamic data pulling incorrect info

Hey Bricks community! :smiley:

I have a suuuuper weird issue inside my query loops which just seems to be getting worse. I cannot seem to fix it for the life of me.

Basically, I have a card with a query loop on 2 pages. One is my home page, and one is an archive template.

On my home page, when i use {page_slug}, it just returns ā€˜homeā€™ on all of the items - which I can only assume comes from the home page, even though that isnā€™t the slug.

On my archive template, when I use {page_slug}, it returns memberstack-badge - which is actually the correct slugā€¦ for ONE of the items. But it returns that slug for every single item.

Hereā€™s a loom video where I walk through the problem:
Troubleshooting Dynamic Data Issues šŸ”§ | Loom

Any help would be appreciated, Iā€™m totally lost - thank you so much!!!

Alright so I am almost sure this is a bug at this point - it looks like dynamic data works perfectly fine UNLESS itā€™s being used to set a link destination. Then it goes crazy.

Take a look at this - specifically the link destination in the bottom left corner, and the text below the button that says made-with-memberstack (this is correct)

Now, look at these 2 images. Iā€™m using {post_slug} for both, and yet this one works perfectly (not a link)

And this one doesnā€™t work (is a link)

Hello @juliang,

I tried to replicate the issue, but I canā€™t. Check my screenshot below. First, there is a basic text, with just text, and then there is a button, with a ā€œcustom linkā€. And it works.

So, what if you link the button to {post_url}, using ā€œCustom URLā€ or using ā€œDynamic Dataā€ options? Itā€™s the same?

Can you also make sure that you donā€™t have nested links?

Let me know.
Matej

Hey Matej, thanks for getting back!!

Iā€™ve implemented a temporary solution for now which gets the link value from the hidden text below it and sets it with JavaScript. Itā€™s not a good solution, but itā€™s my interim fix until I figure this out :rofl:

Iā€™ve duplicated the page and removed my temporary fix, so you can test it at Free Bricks Builder Components | One Click Copy | Bricks Board

EDIT: Just re-read your question about post_url and dynamic data - it is indeed the same. The constant I have found is that if itā€™s the URL of a link, it does not work.

Hi,

I tested, but I canā€™t replicate the issue. I see though, that the links in your example, are not working correctly.

Can you send temporary login credentials to your website and a link to this thread to help@bricksbuilder.io using the email address you used during the purchase, so we can take a look?
If you have a staging website, I prefer a staging one :slight_smile:

Thank you.
Matej

No staging website at the moment, but we donā€™t have any visitors yet so no worries if you do break something haha

Sending via email now!

Quick update, if anyone lands here, the issue was a custom code inside the ā€œCustom codeā€ element.

Iā€™ll mark this topic as no-bug, as it was not Bricks-related.

Best regards,
Matej

1 Like

Hey everyone!

This has been resolved - essentially, I had some code which was using WP_Query inside of my query loop which was resetting the $post object.

<?php
$member_id = '{acf_member_id}';

$args = array(
    'post_type'      => 'member', // Correct post type
    'posts_per_page' => 1,
    'meta_query'     => array(
        array(
            'key'   => 'member_id',
            'value' => $member_id,
            'compare' => '='
        )
    )
);

$query = new WP_Query($args);

if ($query->have_posts()) {
    while ($query->have_posts()) {
        $query->the_post();
        $profile_pic_url = get_field('profile_pic_url'); // Get ACF field
        
        // Set default image if profile_pic_url is empty
        if (!$profile_pic_url) {
            $profile_pic_url = '/wp-content/uploads/2025/02/defaultprofpic.webp';
        }

        echo '<img src="' . esc_url($profile_pic_url) . '" alt="Profile Picture" class="member-profile-pic">';
    }
    wp_reset_postdata();
} else {
    echo 'No member found.';
}
?>

Iā€™ve replaced it with this code which I made with ChatGPT

<?php
$member_id = get_field('member_id', get_the_ID()); // Get the correct member ID

$args = array(
    'post_type'      => 'member',
    'posts_per_page' => 1,
    'meta_query'     => array(
        array(
            'key'   => 'member_id',
            'value' => $member_id,
            'compare' => '='
        )
    )
);

// Use get_posts() instead of WP_Query to avoid modifying the global $post
$members = get_posts($args);

if (!empty($members)) {
    $member = $members[0]; // Get the first result
    $name = get_field('name', $member->ID); // Get ACF field for this member
    echo esc_html($name);
}
?>

This one uses get_posts instead of WP_Query - so, no more problem!

Big thanks to @Matej for the amazing support. Hope this thread helps someone in the future!

2 Likes