Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to display metabox repeater fields on the frontend.

Here is the code to setup the metabox repeater fields:

$my_meta =  new AT_Meta_Box($config);  

$repeater_fields[] = $my_meta->addText($prefix.'t_field_id',array('name'=> 'Title'),true);
$repeater_fields[] = $my_meta->addText($prefix.'d_field_id',array('name'=> 'Description'),true);
$repeater_fields[] = $my_meta->addText($prefix.'p_field_id',array('name'=> 'Price'),true);
$repeater_fields[] = $my_meta->addImage($prefix.'i_field_id',array('name'=> 'Image'),true);
$my_meta->addRepeaterBlock($prefix.'re_',array('inline' => true, 'name' => 'This is a Repeater Block','fields' => $repeater_fields));      
$my_meta->Finish();

I tried to use this code:

$title = get_post_meta(get_the_ID(),'mt_t_field_id',true); 
                    echo $title;

Any advice?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Nice to see people using my class :)

Anyway when you save a field in a repeater block , to access the data you need to use the repeater ID which in your case it's

   $repeater_data = get_post_meta(get_the_ID(),$prefix.'re_',true);

and this returns an array of arrays with the id as key and value as value so you can loop over the array like this:

foreach($repeater_data as $arr){
   echo 'title: ' . $arr[$prefix.'t_field_id'];
   echo '<br />Description: ' . $arr[$prefix.'d_field_id'];
   echo '<br />Price: ' . $arr[$prefix.'p_field_id'];
   echo '<br />image: <img src="' . $arr[$prefix.'i_field_id']['url']">';
}

to understand better how an image field is stored take a look at the class's wiki or the comments on this post

share|improve this answer
    
you rocks thanks so much !! –  wordpress nooby Apr 2 '12 at 12:04
    
just a little question, why the foreach data return an invalid argument supplied... $repeater_data is an array ? –  wordpress nooby Apr 2 '12 at 15:14
    
I can't tell without seeing your code, but you can simply do a var_dump($repeater_data); once to see whats going on there. –  Bainternet Apr 2 '12 at 15:21
    
ok all is fine i was make a mistake with the $prefix... so noob :) all apologies and thanks again sir –  wordpress nooby Apr 2 '12 at 15:27
    
Glad it worked out for you –  Bainternet Apr 2 '12 at 15:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.