<?php defined('ABSPATH') or die('No script kiddies please!');

 ?>
<div class="wpwab-field-wrap wpwab-field-post-multi" >
    <label><?php _e('Select Post', wpwab_TD); ?></label>
    <div class="wpwab-field">
        <div id="wpwab_posts_content">
            <?php
            $current_page = intval($_POST['page_num']);
            $limit = 10;
            $args = array(
                'post_type' => 'post',
                'posts_per_page' => $limit,
                'order' => 'DESC',
                'orderby' => 'ID',
                'paged' => $current_page
            );
            $query = new WP_Query($args);
            $selected_posts = (!empty($_POST['selected_posts'])) ? explode(',', $_POST['selected_posts']) : array();
            $rowCount = $query->found_posts;

            //Initialize Pagination class and create object
            //$url = wpwab_URL . 'inc/backend/pagination/wpwab-getpaginatepage.php';

            $pagConfig = array('baseURL' => $url, 'select_type' => $select_type, 'totalRows' => $rowCount, 'perPage' => $limit, 'contentDiv' => 'wpwab_post_content', 'anchorClass' => 'wpwab-post-trigger', 'currentPage' => $current_page);
            $pagination = new wpwab_Pagination($pagConfig);

            if ($rowCount > 0) {
                ?>
                <div class="wpwab-posts-list">
                    <?php
                    while ($query->have_posts()) : $query->the_post();
                        $post_id = get_the_ID();
                        ?>
                        <div class="wpwab-list-item">
                            <label>
                                <input type="checkbox" id="wpwab-page-<?php esc_attr_e($post_id); ?>"
                                       value="<?php esc_attr_e($post_id); ?>" <?php echo (in_array($post_id, $selected_posts)) ? 'checked="checked"' : ''; ?>
                                       data-postname="<?php the_title(); ?>" class="wpwab-postcheckbox-multi"/><?php the_title(); ?>
                            </label>
                        </div>
                    <?php endwhile; ?>
                </div>
                <?php echo $pagination->createLinks();
            }else {
                _e('Posts not found.', wpwab_TD);
            }
            ?>
        </div>
    </div>
</div>

