function alm_query_posts() { $nonce = $_GET['nonce']; $options = get_option('alm_settings'); if (!is_user_logged_in()) { // Skip nonce verification if user is logged in $options = get_option('alm_settings'); // check alm_settings for _alm_nonce_security if (isset($options['_alm_nonce_security']) & $options['_alm_nonce_security'] == '1') { if (!wp_verify_nonce($nonce, 'ajax_load_more_nonce')) { // Check our nonce, if they don't match then bounce! die('Error, could not verify WP nonce.'); } } } $slug = isset($_GET['slug']) ? $_GET['slug'] : ''; $queryType = isset($_GET['query_type']) ? $_GET['query_type'] : 'standard'; // 'standard' or 'totalposts'; totalposts returns $alm_found_posts $cache_id = isset($_GET['cache_id']) ? $_GET['cache_id'] : ''; $repeater = isset($_GET['repeater']) ? $_GET['repeater'] : 'default'; $type = preg_split('/(?=\\d)/', $repeater, 2); // split $repeater value at number to determine type $type = $type[0]; // default | repeater | template_ $theme_repeater = isset($_GET['theme_repeater']) ? $_GET['theme_repeater'] : 'null'; $postType = isset($_GET['post_type']) ? $_GET['post_type'] : 'post'; $post_format = isset($_GET['post_format']) ? $_GET['post_format'] : ''; $category = isset($_GET['category']) ? $_GET['category'] : ''; $category__not_in = isset($_GET['category__not_in']) ? $_GET['category__not_in'] : ''; $tag = isset($_GET['tag']) ? $_GET['tag'] : ''; $tag__not_in = isset($_GET['tag__not_in']) ? $_GET['tag__not_in'] : ''; // Taxonomy $taxonomy = isset($_GET['taxonomy']) ? $_GET['taxonomy'] : ''; $taxonomy_terms = isset($_GET['taxonomy_terms']) ? $_GET['taxonomy_terms'] : ''; $taxonomy_operator = $_GET['taxonomy_operator']; if (empty($taxonomy_operator)) { $taxonomy_operator = 'IN'; } $taxonomy_relation = isset($_GET['taxonomy_relation']) ? $_GET['taxonomy_relation'] : 'AND'; if ($taxonomy_relation == '') { $taxonomy_relation = 'AND'; } // Date $year = isset($_GET['year']) ? $_GET['year'] : ''; $month = isset($_GET['month']) ? $_GET['month'] : ''; $day = isset($_GET['day']) ? $_GET['day'] : ''; // Custom Fields $meta_key = isset($_GET['meta_key']) ? $_GET['meta_key'] : ''; $meta_value = isset($_GET['meta_value']) ? $_GET['meta_value'] : ''; $meta_compare = $_GET['meta_compare']; if ($meta_compare == '') { $meta_compare = 'IN'; } if ($meta_compare === 'lessthan') { $meta_compare = '<'; } // do_shortcode fix (shortcode was rendering as HTML) if ($meta_compare === 'lessthanequalto') { $meta_compare = '<='; } // do_shortcode fix (shortcode was rendering as HTML) $meta_relation = $_GET['meta_relation']; if ($meta_relation == '') { $meta_relation = 'AND'; } $meta_type = $_GET['meta_type']; if ($meta_type == '') { $meta_type = 'CHAR'; } $s = isset($_GET['search']) ? $_GET['search'] : ''; $custom_args = isset($_GET['custom_args']) ? $_GET['custom_args'] : ''; $author_id = isset($_GET['author']) ? $_GET['author'] : ''; // Ordering $order = isset($_GET['order']) ? $_GET['order'] : 'DESC'; $orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'date'; // Include, Exclude, Offset, Status $post__in = isset($_GET['post__in']) ? $_GET['post__in'] : ''; $post__not_in = isset($_GET['post__not_in']) ? $_GET['post__not_in'] : ''; $exclude = isset($_GET['exclude']) ? $_GET['exclude'] : ''; $offset = isset($_GET['offset']) ? $_GET['offset'] : 0; $post_status = $_GET['post_status']; if ($post_status == '') { $post_status = 'publish'; } // Page $numPosts = isset($_GET['posts_per_page']) ? $_GET['posts_per_page'] : 5; $page = isset($_GET['pageNumber']) ? $_GET['pageNumber'] : 0; // Preload Add-on $preloaded = isset($_GET['preloaded']) ? $_GET['preloaded'] : 'false'; $preloaded_amount = isset($_GET['preloaded_amount']) ? $_GET['preloaded_amount'] : '5'; if (has_action('alm_preload_installed') && $preloaded === 'true') { // If preload - offset the ajax posts by posts_per_page + preload_amount val $old_offset = $preloaded_amount; $offset = $offset + $preloaded_amount; } //Previous Post Add-on $is_previous_post = isset($_GET['previous_post']) ? $_GET['previous_post'] : false; $previous_post_id = isset($_GET['previous_post_id']) ? $_GET['previous_post_id'] : ''; //SEO Add-on $seo_start_page = isset($_GET['seo_start_page']) ? $_GET['seo_start_page'] : 1; // Language (Is this needed?) $lang = isset($_GET['lang']) ? $_GET['lang'] : ''; // Set up initial args $paged = get_query_var('paged') ? get_query_var('paged') : 1; $args = array('post_type' => $postType, 'posts_per_page' => $numPosts, 'offset' => $offset + $numPosts * $page, 'order' => $order, 'orderby' => $orderby, 'post_status' => $post_status, 'ignore_sticky_posts' => false, 'paged' => $paged); // Post Format & Taxonomy // * Both use tax_query, so we need to combine these queries if (!empty($post_format) || !empty($taxonomy)) { $tax_query_total = count(explode(":", $taxonomy)); // Total $taxonomy objects $taxonomy = explode(":", $taxonomy); // convert to array $taxonomy_terms = explode(":", $taxonomy_terms); // convert to array $taxonomy_operator = explode(":", $taxonomy_operator); // convert to array if (empty($taxonomy)) { // Post Format only $args['tax_query'] = array(alm_get_post_format($post_format)); } else { // Taxonomy and possibly Post Formats if ($tax_query_total === 1) { $args['tax_query'] = array('relation' => $taxonomy_relation, alm_get_post_format($post_format), alm_get_taxonomy_query($taxonomy[0], $taxonomy_terms[0], $taxonomy_operator[0])); } if ($tax_query_total === 2) { $args['tax_query'] = array('relation' => $taxonomy_relation, alm_get_post_format($post_format), alm_get_taxonomy_query($taxonomy[0], $taxonomy_terms[0], $taxonomy_operator[0]), alm_get_taxonomy_query($taxonomy[1], $taxonomy_terms[1], $taxonomy_operator[1])); } if ($tax_query_total === 3) { $args['tax_query'] = array('relation' => $taxonomy_relation, alm_get_post_format($post_format), alm_get_taxonomy_query($taxonomy[0], $taxonomy_terms[0], $taxonomy_operator[0]), alm_get_taxonomy_query($taxonomy[1], $taxonomy_terms[1], $taxonomy_operator[1]), alm_get_taxonomy_query($taxonomy[2], $taxonomy_terms[2], $taxonomy_operator[2])); } } } // Category if (!empty($category)) { $args['category_name'] = $category; } // Category Not In if (!empty($category__not_in)) { $exclude_cats = explode(",", $category__not_in); $args['category__not_in'] = $exclude_cats; } // Tag if (!empty($tag)) { $args['tag'] = $tag; } // Tag Not In if (!empty($tag__not_in)) { $exclude_tags = explode(",", $tag__not_in); $args['tag__not_in'] = $exclude_tags; } // Date (not using date_query as there was issue with year/month archives) if (!empty($year)) { $args['year'] = $year; } if (!empty($month)) { $args['monthnum'] = $month; } if (!empty($day)) { $args['day'] = $day; } // Meta Query if (!empty($meta_key) && !empty($meta_value)) { // Parse multiple meta query $meta_query_total = count(explode(":", $meta_key)); // Total meta_query objects $meta_keys = explode(":", $meta_key); // convert to array $meta_value = explode(":", $meta_value); // convert to array $meta_compare = explode(":", $meta_compare); // convert to array $meta_type = explode(":", $meta_type); // convert to array if ($meta_query_total == 1) { $args['meta_query'] = array(alm_get_meta_query($meta_keys[0], $meta_value[0], $meta_compare[0], $meta_type[0])); } if ($meta_query_total == 2) { $args['meta_query'] = array('relation' => $meta_relation, alm_get_meta_query($meta_keys[0], $meta_value[0], $meta_compare[0], $meta_type[0]), alm_get_meta_query($meta_keys[1], $meta_value[1], $meta_compare[1], $meta_type[1])); } if ($meta_query_total == 3) { $args['meta_query'] = array('relation' => $meta_relation, alm_get_meta_query($meta_keys[0], $meta_value[0], $meta_compare[0], $meta_type[0]), alm_get_meta_query($meta_keys[1], $meta_value[1], $meta_compare[1], $meta_type[1]), alm_get_meta_query($meta_keys[2], $meta_value[2], $meta_compare[2], $meta_type[2])); } if ($meta_query_total == 4) { $args['meta_query'] = array('relation' => $meta_relation, alm_get_meta_query($meta_keys[0], $meta_value[0], $meta_compare[0], $meta_type[0]), alm_get_meta_query($meta_keys[1], $meta_value[1], $meta_compare[1], $meta_type[1]), alm_get_meta_query($meta_keys[2], $meta_value[2], $meta_compare[2], $meta_type[2]), alm_get_meta_query($meta_keys[3], $meta_value[3], $meta_compare[3], $meta_type[3])); } } // Meta_key, used for ordering by meta value if (!empty($meta_key)) { $meta_key_single = explode(":", $meta_key); $args['meta_key'] = $meta_key_single[0]; } // Author if (!empty($author_id)) { $args['author'] = $author_id; } // Include posts if (!empty($post__in)) { $post__in = explode(",", $post__in); $args['post__in'] = $post__in; } // Exclude posts if (!empty($post__not_in)) { $post__not_in = explode(",", $post__not_in); $args['post__not_in'] = $post__not_in; } if (!empty($exclude)) { // Deprecate this soon - 2.8.5 */ $exclude = explode(",", $exclude); $args['post__not_in'] = $exclude; } // Search Term if (!empty($s)) { $args['s'] = $s; } // Custom Args if (!empty($custom_args)) { $custom_args_array = explode(";", $custom_args); // Split the $custom_args at ',' foreach ($custom_args_array as $argument) { // Loop each $argument $argument = preg_replace('/\\s+/', '', $argument); // Remove all whitespace $argument = explode(":", $argument); // Split the $argument at ':' $argument_arr = explode(",", $argument[1]); // explode $argument[1] at ',' if (sizeof($argument_arr) > 1) { $args[$argument[0]] = $argument_arr; } else { $args[$argument[0]] = $argument[1]; } } } // Language if (!empty($lang)) { $args['lang'] = $lang; } // Set current page number for determining item number if ($page == 0) { $alm_page_count = 1; } else { $alm_page_count = $page + 1; } // Previous Post Add-on // Hijack $args and and return previous post only if ($is_previous_post == 'true' && has_action('alm_prev_post_installed')) { $args = apply_filters('alm_prev_post_args', $previous_post_id, $postType); } $args = apply_filters('alm_modify_query_args', $args, $slug); // ALM Core Filter Hook // WP_Query() $alm_query = new WP_Query($args); // If preload, set our loop count and total posts to if (has_action('alm_preload_installed') && $preloaded === 'true') { $alm_total_posts = $alm_query->found_posts - $offset + $preloaded_amount; if ($old_offset > 0) { $alm_loop_count = $old_offset; } else { $alm_loop_count = $offset; } } else { $alm_total_posts = $alm_query->found_posts - $offset; $alm_loop_count = 0; } // Create cache directory if (!empty($cache_id) && has_action('alm_cache_create_dir')) { $url = $_SERVER['HTTP_REFERER']; apply_filters('alm_cache_create_dir', $cache_id, $url); $page_cache = ''; // set our page cache variable } if ($queryType === 'standard') { // Run the loop if ($alm_query->have_posts()) { $alm_found_posts = $alm_total_posts; while ($alm_query->have_posts()) { $alm_query->the_post(); $alm_loop_count++; $alm_page = $alm_page_count; // Get page number $alm_item = $alm_page_count * $numPosts - $numPosts + $alm_loop_count; // Get current item if ($theme_repeater != 'null' && has_filter('alm_get_theme_repeater')) { do_action('alm_get_theme_repeater', $theme_repeater, $alm_found_posts, $alm_page, $alm_item); } else { include alm_get_current_repeater($repeater, $type); //Include repeater template } // If ALM Cache is enabled // - Build the cache include and store in $page_cache var if (!empty($cache_id) && has_action('alm_cache_inc')) { $page_cache .= apply_filters('alm_cache_inc', $repeater, $type, $alm_page, $alm_found_posts, $alm_item); } } wp_reset_query(); // If Cache is enabled and seo_start_page is 1 (meaning, a user has not requested /page/12/) // - Only create cached files if the user visits pages in order 1, 2, 3 etc. if (!empty($cache_id) && has_action('alm_cache_installed') && $seo_start_page == 1) { apply_filters('alm_cache_file', $cache_id, $page, $page_cache); } } } elseif ($queryType === 'totalposts') { echo $alm_total_posts; } exit; }
public function alm_query_posts() { $nonce = $_GET['nonce']; $options = get_option('alm_settings'); if (!is_user_logged_in()) { // Skip nonce verification if user is logged in $options = get_option('alm_settings'); // check alm_settings for _alm_nonce_security if (isset($options['_alm_nonce_security']) & $options['_alm_nonce_security'] == '1') { if (!wp_verify_nonce($nonce, 'ajax_load_more_nonce')) { // Check our nonce, if they don't match then bounce! die('Error, could not verify WP nonce.'); } } } $id = isset($_GET['id']) ? $_GET['id'] : ''; $slug = isset($_GET['slug']) ? $_GET['slug'] : ''; $canonical_url = isset($_GET['canonical_url']) ? $_GET['canonical_url'] : $_SERVER['HTTP_REFERER']; $queryType = isset($_GET['query_type']) ? $_GET['query_type'] : 'standard'; // 'standard' or 'totalposts'; totalposts returns $alm_found_posts $cache_id = isset($_GET['cache_id']) ? $_GET['cache_id'] : ''; $repeater = isset($_GET['repeater']) ? $_GET['repeater'] : 'default'; $type = alm_get_repeater_type($repeater); $theme_repeater = isset($_GET['theme_repeater']) ? $_GET['theme_repeater'] : 'null'; $postType = isset($_GET['post_type']) ? $_GET['post_type'] : 'post'; $post_format = isset($_GET['post_format']) ? $_GET['post_format'] : ''; $category = isset($_GET['category']) ? $_GET['category'] : ''; $category__not_in = isset($_GET['category__not_in']) ? $_GET['category__not_in'] : ''; $tag = isset($_GET['tag']) ? $_GET['tag'] : ''; $tag__not_in = isset($_GET['tag__not_in']) ? $_GET['tag__not_in'] : ''; // Taxonomy $taxonomy = isset($_GET['taxonomy']) ? $_GET['taxonomy'] : ''; $taxonomy_terms = isset($_GET['taxonomy_terms']) ? $_GET['taxonomy_terms'] : ''; $taxonomy_operator = $_GET['taxonomy_operator']; if (empty($taxonomy_operator)) { $taxonomy_operator = 'IN'; } $taxonomy_relation = isset($_GET['taxonomy_relation']) ? $_GET['taxonomy_relation'] : 'AND'; if ($taxonomy_relation == '') { $taxonomy_relation = 'AND'; } // Date $year = isset($_GET['year']) ? $_GET['year'] : ''; $month = isset($_GET['month']) ? $_GET['month'] : ''; $day = isset($_GET['day']) ? $_GET['day'] : ''; // Custom Fields $meta_key = isset($_GET['meta_key']) ? $_GET['meta_key'] : ''; $meta_value = isset($_GET['meta_value']) ? $_GET['meta_value'] : ''; $meta_compare = $_GET['meta_compare']; if ($meta_compare == '') { $meta_compare = 'IN'; } if ($meta_compare === 'lessthan') { $meta_compare = '<'; } // do_shortcode fix (shortcode was rendering as HTML) if ($meta_compare === 'lessthanequalto') { $meta_compare = '<='; } // do_shortcode fix (shortcode was rendering as HTML) $meta_relation = $_GET['meta_relation']; if ($meta_relation == '') { $meta_relation = 'AND'; } $meta_type = $_GET['meta_type']; if ($meta_type == '') { $meta_type = 'CHAR'; } $s = isset($_GET['search']) ? $_GET['search'] : ''; $custom_args = isset($_GET['custom_args']) ? $_GET['custom_args'] : ''; // Author $author = isset($_GET['author']) ? $_GET['author'] : ''; // Ordering $order = isset($_GET['order']) ? $_GET['order'] : 'DESC'; $orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'date'; // Include, Exclude, Offset, Status $post__in = isset($_GET['post__in']) ? $_GET['post__in'] : ''; $post__not_in = isset($_GET['post__not_in']) ? $_GET['post__not_in'] : ''; $exclude = isset($_GET['exclude']) ? $_GET['exclude'] : ''; $offset = isset($_GET['offset']) ? $_GET['offset'] : 0; $post_status = $_GET['post_status']; if ($post_status == '') { $post_status = 'publish'; } if ($post_status != 'publish' && $post_status != 'inherit') { // If not 'publish', OR 'inherit' confirm user has rights to view these old posts. if (current_user_can('edit_theme_options')) { $post_status = $post_status; } else { $post_status = 'publish'; } } // Page Parameters $posts_per_page = isset($_GET['posts_per_page']) ? $_GET['posts_per_page'] : 5; $page = isset($_GET['page']) ? $_GET['page'] : 0; // Preload Add-on $preloaded = isset($_GET['preloaded']) ? $_GET['preloaded'] : 'false'; $preloaded_amount = isset($_GET['preloaded_amount']) ? $_GET['preloaded_amount'] : '5'; if (has_action('alm_preload_installed') && $preloaded === 'true') { // If preload - offset the ajax posts by posts_per_page + preload_amount val $old_offset = $preloaded_amount; $offset = $offset + $preloaded_amount; } // CTA Add-on $cta = false; $ctaData = isset($_GET['cta']) ? $_GET['cta'] : ''; if ($ctaData) { $cta = true; $cta_position = isset($ctaData['cta_position']) ? $ctaData['cta_position'] : 'before:1'; $cta_position_array = explode(":", $cta_position); $cta_pos = (string) $cta_position_array[0]; $cta_val = (string) $cta_position_array[1]; if ($cta_pos != 'after') { $cta_pos = 'before'; } $cta_repeater = isset($ctaData['cta_repeater']) ? $ctaData['cta_repeater'] : 'null'; $cta_theme_repeater = isset($ctaData['cta_theme_repeater']) ? $ctaData['cta_theme_repeater'] : 'null'; } // Previous Post Add-on $is_previous_post = isset($_GET['previous_post']) ? $_GET['previous_post'] : false; $previous_post_id = isset($_GET['previous_post_id']) ? $_GET['previous_post_id'] : ''; // Paging Add-on $paging = isset($_GET['paging']) ? $_GET['paging'] : false; // SEO Add-on $seo_start_page = isset($_GET['seo_start_page']) ? $_GET['seo_start_page'] : 1; // Language (Is this required?) $lang = isset($_GET['lang']) ? $_GET['lang'] : ''; // Set up initial query arguments $paged = get_query_var('paged') ? get_query_var('paged') : 1; $args = array('post_type' => $postType, 'posts_per_page' => $posts_per_page, 'offset' => $offset + $posts_per_page * $page, 'order' => $order, 'orderby' => $orderby, 'post_status' => $post_status, 'ignore_sticky_posts' => false, 'paged' => $paged); // Paging // If !paging, turn off pagination information to improve wp_query performance if (!$paging) { $args['no_found_rows'] = true; } // Post Format & Taxonomy // - Both use tax_query, so we combine these queries if (!empty($post_format) || !empty($taxonomy)) { $tax_query_total = count(explode(":", $taxonomy)); // Total $taxonomy objects $taxonomy = explode(":", $taxonomy); // convert to array $taxonomy_terms = explode(":", $taxonomy_terms); // convert to array $taxonomy_operator = explode(":", $taxonomy_operator); // convert to array if (empty($taxonomy)) { // Post Format only $args['tax_query'] = array(alm_get_post_format($post_format)); } else { // Post Formats $args['tax_query'] = array('relation' => $taxonomy_relation, alm_get_post_format($post_format)); // Loop Taxonomies for ($tax_i = 0; $tax_i < $tax_query_total; $tax_i++) { $args['tax_query'][] = alm_get_taxonomy_query($taxonomy[$tax_i], $taxonomy_terms[$tax_i], $taxonomy_operator[$tax_i]); } } } // Category if (!empty($category)) { $args['category_name'] = $category; } // Category Not In if (!empty($category__not_in)) { $exclude_cats = explode(",", $category__not_in); $args['category__not_in'] = $exclude_cats; } // Tag if (!empty($tag)) { $args['tag'] = $tag; } // Tag Not In if (!empty($tag__not_in)) { $exclude_tags = explode(",", $tag__not_in); $args['tag__not_in'] = $exclude_tags; } // Date (not using date_query as there was issue with year/month archives) if (!empty($year)) { $args['year'] = $year; } if (!empty($month)) { $args['monthnum'] = $month; } if (!empty($day)) { $args['day'] = $day; } // Meta Query if (!empty($meta_key) && !empty($meta_value) || !empty($meta_key) && $meta_compare !== "IN") { // Parse multiple meta query $meta_query_total = count(explode(":", $meta_key)); // Total meta_query objects $meta_keys = explode(":", $meta_key); // convert to array $meta_value = explode(":", $meta_value); // convert to array $meta_compare = explode(":", $meta_compare); // convert to array $meta_type = explode(":", $meta_type); // convert to array if ($meta_query_total == 1) { $args['meta_query'] = array(alm_get_meta_query($meta_keys[0], $meta_value[0], $meta_compare[0], $meta_type[0])); } if ($meta_query_total == 2) { $args['meta_query'] = array('relation' => $meta_relation, alm_get_meta_query($meta_keys[0], $meta_value[0], $meta_compare[0], $meta_type[0]), alm_get_meta_query($meta_keys[1], $meta_value[1], $meta_compare[1], $meta_type[1])); } if ($meta_query_total == 3) { $args['meta_query'] = array('relation' => $meta_relation, alm_get_meta_query($meta_keys[0], $meta_value[0], $meta_compare[0], $meta_type[0]), alm_get_meta_query($meta_keys[1], $meta_value[1], $meta_compare[1], $meta_type[1]), alm_get_meta_query($meta_keys[2], $meta_value[2], $meta_compare[2], $meta_type[2])); } if ($meta_query_total == 4) { $args['meta_query'] = array('relation' => $meta_relation, alm_get_meta_query($meta_keys[0], $meta_value[0], $meta_compare[0], $meta_type[0]), alm_get_meta_query($meta_keys[1], $meta_value[1], $meta_compare[1], $meta_type[1]), alm_get_meta_query($meta_keys[2], $meta_value[2], $meta_compare[2], $meta_type[2]), alm_get_meta_query($meta_keys[3], $meta_value[3], $meta_compare[3], $meta_type[3])); } } // Meta_key if (!empty($meta_key)) { // ordering by meta value if (strpos($orderby, 'meta_value') !== false) { // Only order by meta_key, if $orderby is set to meta_value{_num} $meta_key_single = explode(":", $meta_key); $args['meta_key'] = $meta_key_single[0]; } } // Author if (!empty($author)) { $args['author'] = $author; } // Include posts if (!empty($post__in)) { $post__in = explode(",", $post__in); $args['post__in'] = $post__in; } // Exclude posts if (!empty($post__not_in)) { $post__not_in = explode(",", $post__not_in); $args['post__not_in'] = $post__not_in; } if (!empty($exclude)) { // Deprecate this soon - 2.8.5 */ $exclude = explode(",", $exclude); $args['post__not_in'] = $exclude; } // Search Term if (!empty($s)) { $args['s'] = $s; } // Custom Args if (!empty($custom_args)) { $custom_args_array = explode(";", $custom_args); // Split the $custom_args at ',' foreach ($custom_args_array as $argument) { // Loop each $argument $argument = preg_replace('/\\s+/', '', $argument); // Remove all whitespace $argument = explode(":", $argument); // Split the $argument at ':' $argument_arr = explode(",", $argument[1]); // explode $argument[1] at ',' if (sizeof($argument_arr) > 1) { $args[$argument[0]] = $argument_arr; } else { $args[$argument[0]] = $argument[1]; } } } // Language if (!empty($lang)) { $args['lang'] = $lang; } // Set current page number for determining item number if ($page == 0) { $alm_page_count = 1; } else { $alm_page_count = $page + 1; } /* * alm_prev_post_args * * Previous Post Add-on hook * Hijack $args and and return previous post only $args * * @return $args; */ if ($is_previous_post == 'true' && has_action('alm_prev_post_installed')) { $args = apply_filters('alm_prev_post_args', $previous_post_id, $postType); } /* * alm_modify_query_args * * ALM Core Filter Hook * * @return $args; */ $args = apply_filters('alm_modify_query_args', $args, $slug); // ALM Core Filter Hook /* * alm_query_args_[id] * * ALM Core Filter Hook * * @return $args; */ $args = apply_filters('alm_query_args_' . $id, $args); // ALM Core Filter Hook /* * WP_Query * * ALM Query * * @return $alm_query; */ $alm_query = new WP_Query($args); // WP_Query() // If preload, update our loop count and total posts if (has_action('alm_preload_installed') && $preloaded === 'true') { $alm_total_posts = $alm_query->found_posts - $offset + $preloaded_amount; if ($old_offset > 0) { $alm_loop_count = $old_offset; } else { $alm_loop_count = $offset; } } else { $alm_total_posts = $alm_query->found_posts - $offset; $alm_loop_count = 0; } /* * alm_cache_create_dir * * Cache Add-on hook * Create cache directory + meta .txt file * * @return null */ if (!empty($cache_id) && has_action('alm_cache_create_dir')) { apply_filters('alm_cache_create_dir', $cache_id, $canonical_url); $page_cache = ''; // set our page cache variable } if ($queryType === 'standard') { // Run the loop if ($alm_query->have_posts()) { $alm_found_posts = $alm_total_posts; $alm_post_count = $alm_query->post_count; $alm_current = 0; $alm_has_cta = false; $cta_array = array(); if ($cta && has_action('alm_cta_pos_array')) { // Build CTA Position Array $cta_array = apply_filters('alm_cta_pos_array', $seo_start_page, $page, $posts_per_page, $alm_post_count, $cta_val, $cta_repeat); } ob_start(); // ALM Loop while ($alm_query->have_posts()) { $alm_query->the_post(); $alm_loop_count++; $alm_current++; $alm_page = $alm_page_count; // Get page number $alm_item = $alm_page_count * $posts_per_page - $posts_per_page + $alm_loop_count; // Get current item // Call to Action [Before] if ($cta && has_action('alm_cta_inc') && $cta_pos === 'before' && in_array($alm_current, $cta_array)) { do_action('alm_cta_inc', $cta_repeater, $cta_theme_repeater, $alm_found_posts, $alm_page, $alm_item, $alm_current, false); $alm_has_cta = true; } // Repeater Template if ($theme_repeater != 'null' && has_action('alm_get_theme_repeater')) { // Theme Repeater do_action('alm_get_theme_repeater', $theme_repeater, $alm_found_posts, $alm_page, $alm_item, $alm_current); } else { include alm_get_current_repeater($repeater, $type); // Repeater } // End Repeater Template // Call to Action [After] if ($cta && has_action('alm_cta_inc') && $cta_pos === 'after' && in_array($alm_current, $cta_array)) { do_action('alm_cta_inc', $cta_repeater, $cta_theme_repeater, $alm_found_posts, $alm_page, $alm_item, $alm_current, false); $alm_has_cta = true; } } wp_reset_query(); // End ALM Loop $data = ob_get_clean(); /* * alm_cache_file * * Cache Add-on hook * If Cache is enabled, check the cache file * * @return null */ if (!empty($cache_id) && has_action('alm_cache_installed')) { apply_filters('alm_cache_file', $cache_id, $page, $seo_start_page, $data, $preloaded); } /* * alm_debug * * ALM Core Filter Hook * * @return $alm_query/false; */ $debug = apply_filters('alm_debug', false) ? $alm_query : false; $return = array('html' => $data, 'meta' => array('postcount' => $alm_post_count, 'totalposts' => $alm_found_posts, 'debug' => $debug)); wp_send_json($return); } else { $return = array('html' => null, 'meta' => array('postcount' => 0, 'totalposts' => 0, 'debug' => null)); wp_send_json($return); } } elseif ($queryType === 'totalposts') { echo $alm_total_posts; // Paging add-on } wp_die(); }