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

    (@tw2113)

    The BenchPresser

    You should be able to use one by replacing the example you can see below, with your own implementation:

    $group_field_id = $cmb_group->add_field( array(
    		'id'          => $prefix . 'demo',
    		'type'        => 'group',
    		'description' => __( 'Generates reusable form entries', 'cmb2' ),
    		'options'     => array(
    			'group_title'   => __( 'Entry {#}', 'cmb2' ), // {#} gets replaced by row number
    			'add_button'    => __( 'Add Another Entry', 'cmb2' ),
    			'remove_button' => __( 'Remove Entry', 'cmb2' ),
    			'sortable'      => true, // beta
    		),
    	) );

    The only real hickups are going to be getting the post ID accurately and fetching the value based on that.

    I am also looking for the same; want to use one of the Group Field value instead of Entry 1, Entry 2. I see this thread is marked as Resolved but don’t see any specific solution here; can someone please guide me to get the desired result?

    I see the {#} is getting replaced by the code at line 874 in “includes/CMB2_Field.php” file. But not getting hint on how to modify the title of repeating group. Any help please?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    It got marked resolved because we never heard any followup so we assumed it was figured out.

    You can modify the group title to whatever you want by simply replacing the value provided at the following with whatever you want.

    'group_title'   => __( 'Entry {#}', 'cmb2' ), // {#} gets replaced by row number

    You can grab the post ID out of the current url using the $_GET global if you want that. You could also use it to fetch post meta for the post currently being rendered, but keep in mind you may not have a value set yet(like when adding a new post), so provide a fallback value as well.

    Hi,

    Thanks for the reply; I got your idea but that does not resolve the issue. Suppose there are 4 entries added to the Group. If I follow your solution, I can get the array of all entries; but then how to set the Title of collapsible DIV of Group (where usually it says Entry – 1)?

    I want to utilize the value of one of the group fields here. So, for example if I set “Position” group-field value to “Manager”, I want the title of Group to show “Employee – Manager” or something like that. The “group_title” is a generic template which will be applied to all entries inside Group; but I don’t see any way out to set the custom title of each collapsible Group element; and in fact if I follow the original query posted here, it means the same:

    I wish to display one of the field value inside the group filed as the group title instead of Entry 1, Entry 2

    I hope I’ve explained my problem well. Please let me know if any further information from me.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Have you tried dropping in the following to see how it behaves?

    if ( !empty( $_GET ) && isset( $_GET['post'] ) {
        // Grab our desired meta value
        $title = get_post_meta( absint( $_GET['post'] ), 'position', true );
    }
    
    if ( !empty( $title ) ) {
        // If no meta value saved yet, use a default value.
        $title = 'Manager';
    }
    
    ...
    
    'group_title'   => $title

    Interesting solution… thanks; I will try it in a couple of hours from now and will revert back with result.

    Aah, one important thing… the “Position” field is a Repeating Group Field and not the field outside Group. So, the group field value array will hold the value. Since “Position” is a group field, it will have a separate value for every new entry added to the group.

    I will try your solution and will see if I can solve my issue with your proposed solution.

    Talk to you soon…

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Using a repeatable group field value as group title’ is closed to new replies.