【问题标题】:Fieldmanager Wordpress pluginFieldmanager Wordpress 插件
【发布时间】:2015-03-04 14:25:24
【问题描述】:

我需要找到一种方法来显示保存在自定义元框中的值。 Meta Boxes 是使用 WP Fieldmanager 插件创建的。 这是用于在帖子管理中显示字段的代码:

add_action( 'init', function() {
$fm = new Fieldmanager_Group( array(
    'name'           => 'sidebar',
    'limit'          => 0,
    'label'          => 'Sidebar Section',
    'label_macro'    => array( 'Section: %s', 'name' ),
    'add_more_label' => 'Add another Sidebar Section',
    'children'       => array(
        'name'      => new Fieldmanager_Textfield( 'Section Heading' ),
       'item' => new Fieldmanager_Textfield( 'Item', array(
            'limit' => 0,
            'one_label_per_item' => true,
            'add_more_label' => 'Add another Item',

        ) ),

    ),
        )
    );
$fm->add_meta_box( 'Sidebar', array( 'post' ) );
 } );

您可以看到这实际上是一个重复组,其中有一个重复字段。我需要显示这些组的元值。

谢谢。

【问题讨论】:

    标签: wordpress fieldmanager


    【解决方案1】:

    你必须使用 foreach() 来获取内容:

    $repeating_fields = get_post_meta( get_the_ID(), 'sidebar', true); //name of your custom field;
    foreach ($repeating_fields as $repeating_field) {
    print_r($repeating_field[name]); //use here the name given to your children in array to select the correct one;
    }
    

    如果你知道如何安排一个 foreach 循环,你应该会很好。

    如果您想将元框内容作为数组获取,您可以这样做:

    $repeating_fields = get_post_meta( get_the_ID(), 'sidebar', true);
    $name = array(); //define the variable as an array from the start;
    foreach ($repeating_fields as $repeating_field) { //start the loop
    $name[] = $repeating_field[name]; //get the array content from the meta box
    }
    echo $name; //echo the array or parts of it
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多