Fieldmanager Wordpress plugin

928 Views Asked by At

I need to find a way to display values saved in custom meta boxes. Meta Boxes are created with WP Fieldmanager plugin. Here is the code used to display fields in the post admin:

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' ) );
 } );

You can see this is actually a repeating group which has a repeating field inside. I need to display meta values from those groups.

Thanks.

1

There are 1 best solutions below

0
On

You have to use foreach() to get out the content:

$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;
}

From here you if know how to arrange a foreach loop you should be good.

If you want to get the metabox content as an array you can do like this:

$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