0

我在后端侧边栏中有一个自己的选项页面,其中包含这个可重复的字段。(不是元框)我不知道如何在前端的组字段中显示数据。

function ww_register_theme_options() {

$ww_prefix = '_ww_';

$ww_contacts = new_cmb2_box( array(
    'id'           => $ww_prefix . 'ww_option_plugin',
    'title'        => esc_html__( 'Ansprechpartner', 'ww-contact' ),
    'icon_url'     => '/wp-content/plugins/ww-contact/assets/images/icons/ww-icon-white.png',
    'object_types' => array( 'options-page' ),
    'option_key'      => 'ww_options',
) );

$ww_group_field = $ww_contacts->add_field(array(
    'id'          => $ww_prefix . 'contact_repeat_group',
    'type'        => 'group',
    'description' => __('Ansprechparter Liste', 'ww-contact'),
    'repeatable'  => true,
    'options'     => array(
        'group_title'   => 'Ansprechpartner {#}',
        'add_button'    => __('neuer Ansprechpartner', 'ww-contact'),
        'remove_button' => __('Entfernen', 'ww-contact'),
        'sortable'      => true,
    ),
));

$ww_contacts->add_group_field($ww_group_field, array(
    'name' => 'Vorname',
    'id'   => $ww_prefix . 'forname',
    'type' => 'text',
));
$ww_contacts->add_group_field($ww_group_field, array(
    'name' => 'Vorname',
    'id'   => $ww_prefix . 'surname',
    'type' => 'text',
));
}
4

1 回答 1

1

从您的 add_group_field id 中删除它们不需要的前缀。然后像这样循环...

$entries = get_post_meta( $parent, 'ww_contact_repeat_group', true );
if($entries){
    foreach ( (array) $entries as $key => $entry ) {
        if ( isset( $entry['forname'] ) ) {
            $forname = $entry['forname'];
        }
    }
}
于 2018-08-23T01:28:29.357 回答