Форма внешнего интерфейса плагина CMB2 с полем повторителя - PullRequest
0 голосов
/ 23 марта 2020

Я использую плагин cmb2, и у меня есть несколько полей повторителя. Я хочу отправить форму из внешнего интерфейса, который является шаблоном страницы

Поля повторителя похожи на это

add_action( 'cmb2_init', 'yourprefix_register_repeatable_group_field_metabox' );

/ ** * Подключите и добавьте метабокс, чтобы продемонстрировать повторяющиеся сгруппированные поля * / function yourprefix_register_repeatable_group_field_metabox () {

/**
 * Repeatable Field Groups
 */
$cmb_group = new_cmb2_box( array(
    'id'           => 'yourprefix_group_metabox',
    'title'        => esc_html__( 'Songs', 'cmb2' ),
    'object_types' => array( 'album' ),
) );

// $group_field_id is the field id string, so in this case: 'yourprefix_group_demo'
$group_field_id = $cmb_group->add_field( array(
    'id'          => 'yourprefix_group_demo',
    'type'        => 'group',
    'description' => esc_html__( 'Generates reusable form entries', 'cmb2' ),
    'options'     => array(
        'group_title'    => esc_html__( 'Song {#}', 'cmb2' ), // {#} gets replaced by row number
        'add_button'     => esc_html__( 'Add Another Song', 'cmb2' ),
        'remove_button'  => esc_html__( 'Remove Song', 'cmb2' ),
        'sortable'       => true,
        // 'closed'      => true, // true to have the groups closed by default
        // 'remove_confirm' => esc_html__( 'Are you sure you want to remove?', 'cmb2' ), // Performs confirmation before removing group.
    ),
) );

/**
 * Group fields works the same, except ids only need
 * to be unique to the group. Prefix is not needed.
 *
 * The parent field's id needs to be passed as the first argument.
 */
$cmb_group->add_group_field( $group_field_id, array(
    'name'       => esc_html__( 'Song Name', 'cmb2' ),
    'id'         => 'title',
    'type'       => 'text',
    // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
) );

$cmb_group->add_group_field( $group_field_id, array(
    'name'        => esc_html__( 'Song Link', 'cmb2' ),
    'id'          => 'link',
    'type'        => 'text',
) );

} это то, что у меня есть в функциях. php альбома тем - это пользовательский тип записи, и он имеет два поля повторителя 1. song 2.cast и некоторые другие текстовые поля

...