• Resolved llocally

    (@llocally)


    I understand that you can use show_on_cb returning a bolean to extend show_on which only uses post_id / template.

    But I am a little unsure how to achieve this. I want to just have the meta box on homepage when in admin. I can use page ID but intherory that may change

    I tried (is_home()||is_front_page()) but this didn’t work, I guess as conditional tags don’t apply in the back end?

    What am I doing wrong?

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter llocally

    (@llocally)

    Btw I have worked out how to write a custom ‘show on static front page’ for calls from show_on_cb

    e.g.

    function my_show_on_static_front_page(){
        global $post;
        return ($post->ID == get_option( 'page_on_front' ));
     }

    However, I have discovered a bug (feature?) that show_on_cb works fine on normal fields but on group fields, not so. AM I doing something wrong here?

    I think the show_on_cb led me up the garden path for this solution.

    show_on_cb doesn’t appear to work on ‘new_cmb2_box’ and ‘add_group_field’ only on ‘add_field’ (tested with hard coded logic)

    But the solution I actually wanted was simple, after the fact, ignore show_on_cb and just use show_on thus

    'show_on'      => array( 'id' => array( get_option( 'page_on_front' ), ) ),
    Plugin Author Justin Sternberg

    (@jtsternberg)

    Which version are you using? show_on_cb works on grouped fields as well. Also, I just added the show_on_cb parameter for new_cmb2_box, and should be in the next release. And you’re right, conditional tags do not apply in the backend, but you are using the right solution.

    Thread Starter llocally

    (@llocally)

    Hi Justin,

    version 2.0.2

    My ‘bad’ I was trying to use show_on_cd on

    $group_field_id = $cmb_meta->add_field

    which still returns the id (maybe it shouldn’t?)

    where as using shown_on_cb on add_group_field does work

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Ever get this worked out Badlywired?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to extend show_on’ is closed to new replies.