Issue with Custom Looper and zero values

Hey guys,

I’ve come across a bug with a custom looper I’ve been building.

When the looper filter returns a zero, it doesn’t render the value if the fallback has been set - meaning I cannot return a zero. Instead of using the fallback, it simply fails to render the value at all.

Have you seen this before?

Matt

Screenshot 2021-12-23 at 18.53.16 Screenshot 2021-12-23 at 18.53.32

Hello Matt,

Thanks for writing in! Does it display when the fallback is equal to one? We would love to check your custom layout and your looper consumer dynamic element settings. You can create a secure note in your next reply with the following info:
– Link to your site
– WP login URL
– WP username
– WP password
– WP Administrator Role
- Confirmation that we can access and make changes to your site

To know how to create a secure note, please check this out: How The Forum Works

Regards.

Hey there and thanks for replying.

It’s not possible to access the site this week as it’s in active development and I have to get this app out the door!

But I did some testing on the field for you -

  • When the result is 0 and fallback=“0” the output is “”
  • When the result is 0 and the fallack=“1” the output is “1”
  • When the result is NOT 0 and the fallback=“1” the output matches the input.
  • When the result is 0 and the fallback statement is removed, the output = “0”

The function I’m using looks a little like this - it returns an array where one of the columns called “student” is 0 or a positive integer.

function s2w_my_tutor_cohorts($result, $params) {
        global $wpdb;
        $result = $wpdb->get_results(" ***** QUERY REMOVED **** ", ARRAY_A);
    return $result;
}
add_filter( 'cs_looper_custom_tutor_cohorts', 's2w_my_tutor_cohorts', 10, 2);

This works:
<span>{{dc:looper:field key="students"}}</span>

This does not work correctly when students is zero:
<span>{{dc:looper:field key="students" fallback="0"}}</span>

I hope this helps you track it down!

Hello MJ Shelley,

Thanks for the very detailed response. Since the fallback does not help, it is best that you insert 2 Text elements. The first one will contain <span>{{dc:looper:field key="students"}}</span> and then you can add an element condition that it will only display if the {{dc:looper:field key="students"}} >= 1.


And then the second Text element will have <span>0</span> with the element condition of {{dc:looper:field key="students"}} < 1.

If you are not familiar with the element conditions, please check this out:

Hope this helps.

1 Like

Thanks for the solution Ruenel :smiley:

Hi Matt,

Glad that we are able to help you.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.