From a8560e8f2bc11a911046b48994fc098a2f163704 Mon Sep 17 00:00:00 2001 From: Keith Solomon Date: Wed, 12 Mar 2025 11:30:36 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20Fix=20count=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/script.js | 16 ++-------------- resource-filter.php | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/assets/script.js b/assets/script.js index af2b7a0..2f81fda 100644 --- a/assets/script.js +++ b/assets/script.js @@ -111,14 +111,6 @@ jQuery(document).ready(function ($) { }); } - /** - * Handle form submission for filtering resources. - */ - $('#homepage-filter').on('submit', function (e) { - e.preventDefault(); - triggerFiltering(1); // Start at page 1 on new form submission - }); - // Handle sort order change $('#sort-order').on('change', function () { triggerFiltering(); @@ -135,9 +127,7 @@ jQuery(document).ready(function ($) { triggerFiltering(1); }); - /** - * Handle pagination link clicks. - */ + // Handle pagination link clicks. $(document).on('click', '.pagination a', function (e) { e.preventDefault(); @@ -147,9 +137,7 @@ jQuery(document).ready(function ($) { triggerFiltering(paged); }); - /** - * Handle removing individual filters from the "Filters Used" section. - */ + // Handle removing individual filters from the "Filters Used" section. $(document).on('click', '.remove-filter', function (e) { e.preventDefault(); diff --git a/resource-filter.php b/resource-filter.php index abff45d..ca76634 100644 --- a/resource-filter.php +++ b/resource-filter.php @@ -182,11 +182,11 @@ class ContentFilterPlugin { 'type' => 'default' // Accepts 'default' or 'homepage' ], $atts, 'resource_filter'); - ob_start(); - $query = $this->getQuery(); - $resTotal = $query->found_posts; // Default total resource count + define('RF_TOTAL_RESOURCES', $query->found_posts); + + ob_start(); $attTmpl = $this->getTemplate($atts['type']); if (!$attTmpl) { @@ -197,6 +197,7 @@ class ContentFilterPlugin { $summary = rfGetTemplate('filter-summary.php'); $this->includeTemplate($resForm, 'Form template not found.'); + if ($atts['type'] === 'default') { $this->includeTemplate($summary, 'Summary template not found.'); $this->renderResourceResults($query); @@ -266,12 +267,12 @@ class ContentFilterPlugin { } $pagination_links = paginate_links([ - 'total' => $query->max_num_pages, - 'current' => max(1, get_query_var('paged', 1)), - 'format' => '?paged=%#%', + 'total' => $query->max_num_pages, + 'current' => max(1, get_query_var('paged', 1)), + 'format' => '?paged=%#%', 'prev_text' => '«', 'next_text' => '»', - 'type' => 'list' + 'type' => 'list' ]); ?> @@ -293,7 +294,7 @@ class ContentFilterPlugin { $sort_order = isset($_POST['sort_order']) ? sanitize_text_field($_POST['sort_order']) : 'date_desc'; $query_args = [ - 'post_type' => get_option('content_filter_post_types', []), + 'post_type' => get_option('content_filter_post_types', ['post']), 'posts_per_page' => get_option('content_filter_posts_per_page', 12), 'paged' => max(1, get_query_var('paged', 1)), // Get current page number 'tax_query' => $this->buildDynamicTaxQuery(), @@ -335,9 +336,9 @@ class ContentFilterPlugin { return new WP_Query($query_args); } else { return new WP_Query([ - 'post_type' => 'resource', + 'post_type' => get_option('content_filter_post_types', ['post']), 'posts_per_page' => get_option('content_filter_posts_per_page', 12), - 'paged' => max(1, get_query_var('paged', 1)), // Get current page number + 'paged' => max(1, get_query_var('paged', 1)), // Get current page number ]); } } @@ -405,6 +406,7 @@ class ContentFilterPlugin { ]; $query = new WP_Query($query_args); + $resources['count'] = $query->found_posts; $resources = $query->posts; $resResults = rfGetTemplate('resource-results.php');