Add custom fields within meta box class “on the fly”

Agreed, I’ve seen it too, but I don’t think there’s any readily available API or method.

For me, I use a lick of jQuery;

<input type="text" class="list-item" name="list_items[]" />
<input type="button" class="button-secondary" id="add-list" />

<script type="text/javascript">
    ( function( $ ) {
        $( '#add-list' ).click( function() {
            var $item =  $( '.list-item:last' ), $new = $item.clone();
            $item.after( $new.val( '' ) );
        }
    })( jQuery );
</script>

Note that you might wanna tweak those selectors if you plan on having multiple ‘instances’ of these.

Leave a Comment