How do I get this to work

Support MB Builder How do I get this to work

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #46126
    JoeJoe
    Participant

    Hi,

    i have code that works, perfectly in the functions.php, I would like to setup these custom fields via the Metabox backend (graphical backend), Problem I am having is , how do i set and run the function cmb_fields_by_user_role when the box is called in the gfx backend ?

    	$meta_boxes[] = [
            'title'        => __('Custom Metabox'),
            'id'           => 'custom-metabox',
            'post_types'   => ['cpt'], // CPT
            'fields'       => cmb_fields_by_user_role([
                [
                    'type' => 'text',
                    'id'   => 'field_1',
                    'name' => '<h3>Field 1</h3>',
    		'cmb_role'   => array(administrator')
                ],
                [
                    'type' => 'text',
                    'id'   => 'field_2',
                    'name' => '<h3>Field 2</h3>',
    		'cmb_role'   => array('author','administrator')
                ],
                [
                    'type' => 'text',
    				'id'   => 'field_3',
                    'name' => '<h3>Field 3</h3>',
    		'cmb_role'   => array('administrator')
                ]
    #46130
    PeterPeter
    Moderator

    Hello Joe,

    It isn't possible to add the function cmb_fields_by_user_role to the Meta Box registration like that. If you want to show the field group for a specific user, please use the extension MB Include/Exclude. Following the documentation https://docs.metabox.io/extensions/meta-box-include-exclude/

    #46144
    JoeJoe
    Participant

    Thanks Peter, can this be done via the grahical interface ?

    #46149
    PeterPeter
    Moderator

    Hello,

    If you use the builder, please use the option "Advanced location rules" in the field group settings. Please check this screenshot https://imgur.com/lzk0PTd

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.