0

I've a repeater and I want to put another repeater inside of it, but I don't know how! So I want to have a repeater that is inside of another repeater. I'm using it for a trailer I think. And I want to have an input named: Copyright So the parent of copyright is trailer_copyright.

This is my code:

function show_Trailer_MetaBox() {
    global $custom_Trailer_Fields, $post;
    $Trailer_Fields = get_post_meta($post->ID, 'trailers', true);
    wp_nonce_field( 'Trailer_MetaBox_nonce', 'Trailer_MetaBox_nonce' );
    ?>
<script type="text/javascript">
jQuery(document).ready(function($) {
    $('.metabox_submit').click(function(e) {
        e.preventDefault();
        $('#publish').click();
    });
    $('#add-row-trailer').on('click', function() {
        var row = $('.empty-row-trailer.screen-reader-text').clone(true);
        row.removeClass('empty-row-trailer screen-reader-text');
        row.insertBefore('#Trailer_link tbody>tr:last-child');
        return false;
    });
    $('.remove-row-trailer').on('click', function() {
        $(this).parents('tr').remove();
        return false;
    });
    $('#Trailer_link tbody').sortable({
        opacity: 0.6,
        revert: true,
        cursor: 'move',
        handle: '.sort'
    });
});
    </script>
<table id="Trailer_link" width="100%">
    <div class="payam">میتوانید بی نهایت تریلر با کلیک بر روی "<b>افزودن</b>" اضافه کنید</div>
    <tbody>
<?php
    if ( $Trailer_Fields ) :
    foreach ( $Trailer_Fields as $field ) {
?>
<tr>
    <td><a class="button remove-row-trailer" href="#">-</a></td>
    <td>
    <div class="row-meta trailer_title">
    <div class="label"><label for="trailer_title">تیتر تریلر</label></div>
    <div class="input">
    <input type="text" id="trailer_title" class="widefat" name="trailer_title[]" value="<?php if(!empty($field['trailer_title'])) echo esc_attr( $field['trailer_title'] ); ?>" />
    </div>
    </div>
    <div class="row-meta trailer_img">
    <div class="label"><label for="trailer_img">بکگراند تریلر</label></div>
    <div class="input">
    <input type="text" id="trailer_img" class="widefat" name="trailer_img[]" value="<?php if(!empty($field['trailer_img'])) echo esc_attr( $field['trailer_img'] ); ?>" />
    </div>
    </div>
    <div class="row-meta trailer_link">
    <div class="label"><label for="trailer_link">لینک تریلر</label></div>
    <div class="input">
    <input type="text" id="trailer_link" class="widefat" name="trailer_link[]" value="<?php if(!empty($field['trailer_link'])) echo esc_attr( $field['trailer_link'] ); ?>" />
    </div>
    </div>
    <div class="second-repeater">

    </div>
    </td>
    <td><a class="sort"><i class="icon_move"></i></a></td>
</tr>
<?php
}
else :
// show a blank one
?>
<tr>
    <td><a class="button remove-row-trailer" href="#">-</a></td>
    <td>
    <div class="row-meta trailer_title">
    <div class="label"><label for="trailer_title">تیتر تریلر</label></div>
    <div class="input">
    <input type="text" id="trailer_title" class="widefat" name="trailer_title[]"/>
    </div>
    </div>
    <div class="row-meta trailer_img">
    <div class="label"><label for="trailer_img">بکگراند تریلر</label></div>
    <div class="input">
    <input type="text" id="trailer_img" class="widefat" name="trailer_img[]" />
    </div>
    </div>
    <div class="row-meta trailer_link">
    <div class="label"><label for="trailer_link">لینک تریلر</label></div>
    <div class="input">
    <input type="text" id="trailer_link" class="widefat" name="trailer_link[]" />
    </div>
    </div>
    <div class="second-repeater">

    </div>
    </td>
    <td><a class="sort"><i class="icon_move"></i></a></td>
</tr>
<?php endif; ?>
<!-- empty hidden one for jQuery -->
<tr class="empty-row-trailer screen-reader-text">
    <td><a class="button remove-row-trailer" href="#">-</a></td>
    <td>
    <div class="row-meta trailer_title">
    <div class="label"><label for="trailer_title">تیتر تریلر</label></div>
    <div class="input">
    <input type="text" id="trailer_title" class="widefat" name="trailer_title[]"/>
    </div>
    </div>
    <div class="row-meta trailer_img">
    <div class="label"><label for="trailer_img">بکگراند تریلر</label></div>
    <div class="input">
    <input type="text" id="trailer_img" class="widefat" name="trailer_link[]" />
    </div>
    </div>
    <div class="row-meta trailer_link">
    <div class="label"><label for="trailer_link">لینک تریلر</label></div>
    <div class="input">
    <input type="text" id="trailer_link" class="widefat" name="trailer_link[]" />
    </div>
    </div>
    <div class="second-repeater">

    </div>
    </td>
    <td><a class="sort"><i class="icon_move"></i></a></td>
</tr>
</tbody>
</table>
<p><a id="add-row-trailer" class="button button-primary button-large" href="#">افزودن</a>
</p>
<?php
echo '</div>';
    }
function save_Trailer_meta($post_id) {
    if ( ! isset( $_POST['Trailer_MetaBox_nonce'] ) ||
    ! wp_verify_nonce( $_POST['Trailer_MetaBox_nonce'], 'Trailer_MetaBox_nonce' ) )
        return;

    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
        return;

    if (!current_user_can('edit_post', $post_id))
        return;

    $old = get_post_meta($post_id, 'trailers', true);
    $new = array();
    $trailer_title = $_POST['trailer_title'];
    $trailer_link = $_POST['trailer_link'];
    $trailer_img = $_POST['trailer_img'];
     $count = count( $trailer_title );
     for ( $i = 0; $i < $count; $i++ ) {
        if ( $trailer_title[$i] != '' ) :
            $new[$i]['trailer_title'] = stripslashes( strip_tags( $trailer_title[$i] ) );
            $new[$i]['trailer_link'] = stripslashes( $trailer_link[$i] );
            $new[$i]['trailer_img'] = stripslashes( strip_tags( $trailer_img[$i] ) );
        endif;
    }
    if ( !empty( $new ) && $new != $old )
        update_post_meta( $post_id, 'trailers', $new );
    elseif ( empty($new) && $old )
        delete_post_meta( $post_id, 'trailers', $old );


}
add_action('save_post', 'save_Trailer_meta');

And I want to put the second repeater inside of a div with class of "second-repeater"

This is the div:

<div class="second-repeater">

</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.