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 am making theme for hotel and i made custom metabox with list of various custom fields that i would need in posts.

What i did is i made a list of fields like

  • booking
  • wifienabled
  • coffe
  • pool
  • spa

and so on...

Problem is that currently i can show those custom fields in website frontend only by order how i added them in array, if i change places in my list custom fields will change places in website frontend.

Is it possible that custom fields have specific order? Some kind of drag and drop to rearange those fields and change order of display in frontend?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

In this example of repeatable custom fields, we can see that the following jQuery is needed:

$('#repeatable-fieldset-one tbody').sortable({
    opacity: 0.6,
    revert: true,
    cursor: 'move',
    handle: '.sort'
});

And the HTML it controls is (simplified):

<table id="repeatable-fieldset-one" width="100%">
<thead>
    <tr>
        <th width="2%"></th>
        <th width="30%">Name</th>
        <th width="60%">URL</th>
        <th width="2%"></th>
    </tr>
</thead>
<tbody>
<?php
if ( $repeatable_fields ) :
    foreach ( $repeatable_fields as $field ) {
    ?>
        <tr>
            <td><a class="button remove-row" href="#">-</a></td>
            <td>NAME FIELD</td>
            <td>URL FIELD</td>
            <td><a class="sort">|||</a></td>
        </tr>
    <?php
    }
endif;
share|improve this answer
    
This is great, not exactly what i had in mind, i just wanted to be able to reorder my fields, but this is even better, i added select box to this and now i can add multiple fields. Like coffee text outside, coffee text inside. Thanks alot you helped so much. –  Aleksandar Đorđević Feb 7 '13 at 10:31
    
One stupid question. How do i display this list in my theme? –  Aleksandar Đorđević Feb 7 '13 at 10:59
    
Glad it helped! In the theme use get_post_meta and you'll have an array with the values. –  brasofilo Feb 7 '13 at 13:36
    
I got it working, i just didn't realized at first that it has an array inside an array of list. –  Aleksandar Đorđević Feb 7 '13 at 13:49
    
How do i add radio buttons list to this ? –  Aleksandar Đorđević Feb 7 '13 at 23:04

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.