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'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

1 Answer 1

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 :

    <?php
        while($mb->have_fields_and_multi('types')):
        $mb->the_group_open();
        $mb->the_field('type');
    ?>
    <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>
    <?php
        $mb->the_group_close();
        endwhile;
    ?>
    <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 :

    <?php
        while($mb->have_fields_and_multi('details')):
        $mb->the_group_open();
        $mb->the_field('detail_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 } ?>
    </select>
    <?php $mb->the_field('detail_title'); ?>
    <label>Description</label>
    <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>
    <?php
        $mb->the_group_close();
        endwhile;
    ?>
    <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

 
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.