function xt_ajax_get_posts() { global $post, $tab_post_category, $tab_post_author, $tab_post_date, $tab_post_stats; $tab = array(); if (!empty($_POST["settings"])) { $tab = unserialize(xt_64_decode($_POST["settings"])); } $cpage = 1; if (!empty($_POST["cpage"])) { $cpage = filter_input(INPUT_POST, 'cpage', FILTER_VALIDATE_INT); } $direction = 'prev'; if (!empty($_POST["direction"])) { $direction = sanitize_text_field($_POST["direction"]); } $per_page = $tab['posts_per_page']; $query = $tab['query']; $query_post_formats = $tab['query_post_formats']; $format = $tab['format']; $include_posts = false; if ($query == 'selection') { $include_posts = $tab['include_posts']; } $tab_post_category = $tab['show_post_category']; $tab_post_author = $tab['show_post_author']; $tab_post_date = $tab['show_post_date']; $tab_post_stats = $tab['show_post_stats']; $posts = xt_get_posts(array('direction' => 'prev', 'per_page' => $per_page, 'query' => $query, 'query_post_formats' => $query_post_formats, 'format' => $format, 'include_posts' => $include_posts, 'cpage' => $cpage)); $result = array(); ob_start(); foreach ($posts as $post) { setup_postdata($post); include locate_template('parts/items/post-tab-item.php'); } $result[$direction . "_tab_items"] = ob_get_contents(); ob_end_clean(); ob_start(); foreach ($posts as $post) { setup_postdata($post); include locate_template('parts/items/post-full.php'); } $result[$direction . "_content_items"] = ob_get_contents(); ob_end_clean(); die(json_encode($result)); }
$include_posts = false; $query_post_formats = false; $format = false; if ($query == 'selection') { $include_posts = $tab['include_posts']; } else { $query_post_formats = $tab['query_post_formats']; if ($query_post_formats) { $format = $tab['format']; } } $tab_post_category = $tab['show_post_category']; $tab_post_author = $tab['show_post_author']; $tab_post_date = $tab['show_post_date']; $tab_post_stats = $tab['show_post_stats']; $posts = xt_get_posts(array('direction' => 'prev', 'per_page' => $per_page, 'query' => $query, 'include_posts' => $include_posts, 'query_post_formats' => $query_post_formats, 'format' => $format)); $tab_posts[$i] = $posts; ?> <div class="content<?php echo $i == 0 ? ' active' : ''; ?> " id="tab_<?php echo esc_attr($i); ?> " data-action="xt_ajax_get_posts" data-settings="<?php echo esc_attr(xt_64_encode(serialize($tab))); ?> ">