• Resolved samtempleman

    (@samtempleman)


    PROBLEM
    I have a special case where I’m outputting a bit of custom HTML after each item in a group field. For this I’m using a custom after_group_row callback function. My callback function works with one exception: the dynamic values that I’m trying to output as part of the HTML string are cached by CMB2, so only the values for Row 1 are returned for all rows.

    Here is a gist showing my metabox and callback function.

    HACKY SOLUTION
    Looking at the CMB2 changelog I found the unset_param_callback_cache() function. If I hack the CMB2 source file CMB2.php to add this line
    $field_group->unset_param_callback_cache( 'after_group_row' );
    at the top of the render_group_row() function definition (starting about line 594), it works and my callback returns fresh values.

    Of course, I’d rather not modify the CMB2 plugin files if I can help it. Is there a way to leverage unset_param_callback_cache() without messing with core files? Or perhaps another method of bypassing the cache?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Checking on some things with this one, as I’m not super familiar with this cache mechanism that I had never noticed before.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Got some feedback and what I’m being told is that repeatable groups are repeated with JS. So even if you could get the desired result, you’re still going to have to deal with the thing being duplicated when a new group is added and thus end up in the same place as you are now, needing a JS solution too.

    Thread Starter samtempleman

    (@samtempleman)

    @tw2113 thanks for looking into this! Sounds like unset_param_callback_cache() is only meant as a core helper function then. With that in mind I’ll consider my current solution as good enough for now.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Sounds good. Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to bypass cached results?’ is closed to new replies.