WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm building a quite complex custom post type structure and I would need some help regarding my metaboxes.

What I want to do:

  1. Thank's to the have_fields_and_multi() function, the user enters data in simple text input fields (with a "Add new" button)
  2. The values from the previous text inputs should be used to build a select dropdown in another metabox.

To make it simple, here is a mockup (also attached to this post): http://idzr.org/0c95

I have the first part working, it's easy. But I can't figure out how to make the second part to work. If I use a while($mb->have_fields_and_multi('aaa')) in another while($mb->have_fields_and_multi('bbb')) the page is infinite (the loop doesn't end. If I use foreach I have other problems.

Do you have an idea about how I can achieve this ? Thanks!!!

share|improve this question
The link doesn't work. You can also upload images here directly. – kaiser May 31 '11 at 17:08
@kaiser I edited the link. (I can't post captures as it was my first post in this StackExchange website) – Sinklar Jun 1 '11 at 5:34
up vote 2 down vote accepted

Ok, I finally managed to solve that by myself. It is possible thanks to :

  1. Create the first field :

    <input type="text" id="<?php $mb->the_name(); ?>" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>" />
    <a href="#" class="dodelete button">Remove</a>
    <a href="#" class="docopy-types button" style="float: left">Add new</a>
    <a href="#" class="dodelete-types button" style="float: right">Delete all</a>
  2. Create the second batch of fields while using foreach to get the data from the first fields and put that in a select :

    <select name="<?php $mb->the_name(); ?>">
        <option value="">Choose...</option>
        <?php foreach ($meta['types'] as $types) { ?>
        <option value="<?php echo $types['type']; ?>"<?php $mb->the_select_state($types['type']); ?>><?php echo $types['type']; ?></option>
        <?php } ?>
    <?php $mb->the_field('detail_title'); ?>
    <input type="text" id="<?php $mb->the_name(); ?>" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>" /><br />
    <a href="#" class="dodelete button">Remove</a>
    <a href="#" class="docopy-estate_details button">Add new</a>
    <a href="#" class="dodelete-estate_details button">Delete all</a>
share|improve this answer

Your Answer


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.