16 responses to “WPAlchemy MetaBox: Filtering and Repeating Fields”

  1. Tom

    This is so awesome. The features you’ve included in here are really something. I’ll be working with this for a while and will for sure report back with feedback. Thanks a lot Dimas! Also, any word on that coffee/beer button?

  2. Derbois nicolas

    Hi.thanks for your great class, impressive work!
    I’ve just test it on WordPress 3 for custom post type and it’s very easy!
    I specially like the unlimited field option.
    I have test it on a custom box for infinite slider on home page (with an upload btn to choose an image in media library) and it’s very cool!

    I wondering if your class is tested for a long time because i’m interested to use it for my clients website?

  3. Derbois nicolas

    Thanks for your quick answer. I think Iwill test it for my next project.
    One question I’m trying to use the “media box uploder with tickbox” to write values of “group fields (for an unlimited image slider).

    I use a jquery script to open the media uploader and to return the image url to the generated field.

    the problem is that i need to record the post with a value in generated field before being able to have my upload script working.

    Have you ever trying to do such thing?
    Perhaps you can help me?

    Here’s my js script:

    jQuery.noConflict();
    
    jQuery(document).ready(function()
    {
    	jQuery('.upload_input').each(function()
    	{
    		jQuery(this).bind('change focus blur canyon', function()
    		{	
    			$get_div = '#' + jQuery(this).attr('name') + '_preview';
    			$src = '';
    			jQuery($get_div).html('').append($src).find('img');
    		});
    	});
    	
    	$set = jQuery('.set_input');
    	
    	window.get_id = false;
    	
    	$set.click(function()
    	{
    		window.get_id = jQuery(this).attr('id');			
    	});
    	
    	window.original_send_to_editor = window.send_to_editor;
    	window.send_to_editor = function(html)
    	{	
    		if (get_id) 
    		{
    			$img = jQuery(html).attr('src') || jQuery(html).find('img').attr('src') || jQuery(html).attr('href');
    			//jQuery('input[name='+get_id+']').val($img).trigger('canyon');
    			jQuery('input[alt='+get_id+']').val($img).trigger('canyon');
    			get_id = false;
    			window.tb_remove();
    		}else{
    			window.original_send_to_editor(html);
    		}
    	};
    });
    

    Here’s my (your) metabox script:

    	<a href="#" rel="nofollow">Tout effacer
    
    	< ?php have_fields_and_multi('GroupeSliderHome')): ?>
    	< ?php the_group_open(); ?>
     
    		< ?php the_field('slider_home_url'); ?>
    		
    		URL
    
    		<input type="text" name="< ?php the_name(); ?>" alt="uploderhomeslider" value="< ?php the_value(); ?>" class="upload_input" width="100%"/>	
    		<a href="media-upload.php?post_id=0&type=image&TB_iframe=true" id="uploderhomeslider" class="set_input thickbox button" title='Add an Image' onclick="return false;">Choisir le fichier</a>
    		<a href="#" rel="nofollow">Effacer cette image</a>
    
    	< ?php the_group_close(); ?>
    	
    	<a href="#" rel="nofollow">Nouvelle image</a>
    

    [edited] added <pre> … </pre> tags around code, &lt; and &gt; still need to be used inside <pre>

  4. Derbois nicolas

    Yes you have understand.
    Sorry for my bad english ;).

    I think i have a Jquery problem , I will try to fix it.
    Thanks for your help

  5. Derbois Nicolas

    I have succeed to do my unlimited uploader (url return to the field from the wordpress media browser).

    My code is a bit “tricky” but if I’ll enhance.it, I will share it.

    The problem was in the “clone js script” in your MetaBox class. Your original clone script duplicate form elements “id” thats why my other script(which return the url to the field couldn’t work) (the duplicated field with the “display:none” field and with the class ” last tocopy” haved the same Id as the field with the class “last “.

  6. Horia

    Hi Dimas, I am using WPAlchemy and I love it, but I really don’t know how to do this (because I am not a developer) :
    I am trying to create a metabox with a list of books on a custom post type named “Authors”, so the user can check the books the author wrote.

    I take the list of books from the db, store them in $the_books array and try to create a checkbox and a label for every book using WPAlchemy loop :
    while($metabox->have_fields('book', sizeof($the_books))):

    Perhaps my thinking here is wrong, but how would you create something like this ?

    When I check a book and update page, the value is saved fine and I can read it fine on the frontend, but I can’t make it display right in the admin. The problem I think is that when I create this inputs and labels, I use $metabox->the_name() but can’t use $metabox->the_value() because I have to display the name of the books from the array : $the_books[$count_books]->name;.

    Hope you understood the problem and let me know if you think this is possible.
    Thank you.

    Here is the full code I am using in the metabox template :

    get_results('SELECT name FROM wp_wpsc_product_list WHERE active = 1 AND publish = 1');
    ?>
    
    have_fields('book', sizeof($the_books))): ?>
    	
        	<input type="checkbox" name="the_name(); ?>" id="the_name(); ?>" value="name; ?>" get_the_value()) echo ' checked="checked"'; ?> />
            <label for="the_name(); ?>">name; ?> get_the_value()) echo 'value= '.$metabox->get_the_value(); ?>
    
    
  7. daniele m

    nice library!
    there are know bugs/issues?
    ps
    do you have a google group?

  8. James Fishwick

    Excellent work here; I’ll just be throwing out the meta_box functions in all the themes I modify and using yours from here on out.

    Could you help me troubleshoot something? I’m pretty much following your example exactly for an endlessly repeating field, but the “Add” button isn’t actually replicating the field.

    Here is how I create the meta_box instance:

    $sidebar_images_metabox = new WPAlchemy_MetaBox(array
    (
    'id' => '_sidebar_images_meta',
    'title' => 'Sidebar Images',
    'template' => TEMPLATEPATH . '/custom/sidebar_images_meta.php',
    'types' => array('page'),
    'exclude_template' => 'index.php',
    'priority' => 'high'
    ));

    Here is my template:

    <?php while($mb->have_fields_and_multi('sidebar_image')): ?>
    
    <?php $mb->the_group_open(); ?>
     
    	<label>The Image Path</label>
     
    	<p>
    		<?php $mb->the_field('src'); ?>
    		<input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/>
    		<span>Using the "<em>Add an Image</em>" button, Upload an image and paste the URL here. Images will be resized automatically.</span>
    	</p>
     
    	<label>ALT Description <span>(optional)</span></label>
     
    	<p>
    		<?php $mb->the_field('alt'); ?>
    		<textarea name="<?php $mb->the_name(); ?>" rows="3"><?php $mb->the_value(); ?></textarea>
    		<span>Enter in an ALT description.</span>
    	</p>
    
    </div>
    <?php $mb->the_group_close(); ?>
    <?php endwhile; ?>
     
    <p style="margin-bottom:15px; padding-top:5px;"><a href="#" class="docopy-sidebar_image button">Add Anoter Image</a></p>
    

    Again, just can’t get the field to replicate when clicking “Add Another Image.” Any ideas?

  9. Otto Rask

    Hello! Considering repeating fields:

    I’ve been using WPAlchemy on sites for a while now without problems. Now I’ve stumbled upon a problem I can’t seem to solve properly.

    Is it possible to nest two or more ‘have_fields_and_multi’ loops? Every time I insert one into another the script breaks and creates an infinite loop with incorrect field nesting (it keeps creating the same elements inside each instance of itself). In pseudo-code my implementation looks like this:

    while ( $mb -> have_fields_and_multi( ‘foo’ ) ) {
    // Open a new container for a parent item listing
    // e.g. a category of sorts. These should be able
    // to be added as the user wishes.

    while ( $mb -> have_fields_and_multi( ‘bar’ ) ) {
    // Make repeating fields inside the parent
    // category loop.
    } // child loop

    } // parent loop

    (I’ve properly inserted group opens and closes, also the add/delete buttons in their correct locations.)

    This creates an infinite loop and the controls are not working properly (e.g. the inner loop has a ‘dodelete’ -button, but it removes everything including the parent loop in its entirety).

    Is there any workaround to get this functioning properly or should I try some other approach?

  10. Otto Rask

    @Dimas: Okay, thanks for the info! I’ll see if I can manage some other solution to this in the meantime. :)

Leave a Reply