• Resolved Jay Mandell

    (@figo-blac)


    Hello,
    I’ve been trying to use the cmb2_init action hook for the cmb2_get_field_value() helper function based on the documentation. However this did not work as I kept getting an empty string. The documentation has this:

    function cmb2_init_check_field_value() {
        $radio_value = cmb2_get_field_value( 'test_metabox', '_cmb2_test_radio', get_queried_object_id() );
    
        // Perform additional logic based on $radio_value
    }
    add_action( 'cmb2_init', 'cmb2_init_check_field_value' );

    After trying several times I ended up accidentally making a typo that actually worked:

    add_action('cmb2_ini','my_function' );

    Also using add_action('cmb_ini', 'my_function') also works.

    Since it is working, Is it okay to continue using those hooks or will it break at some point in the future?

    https://www.ads-software.com/plugins/cmb2/

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

    (@tw2113)

    The BenchPresser

    Not sure what’s going on with “cmb2_ini” working but not “cmb2_init” because we don’t have any “cmb2_ini” hook in the plugin.

    Thread Starter Jay Mandell

    (@figo-blac)

    This is strange, As it turns out its not that “cmb2_ini” is working, Its seems to work as long as I’m using anything other than “cmb2_init”. Even an empty string works. I have also added to the same file as the example-functions.php file and I have used in another file but same results. Using “cmb2_init” outputs and empty string. But its working now using an empty string so I’m happy ??

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Extremely odd. However, apparently it’s working for you now, which I’ll settle with.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘CMb2_init action hook doesn't seem to work when using helper functions’ is closed to new replies.