diff --git a/assets/script.js b/assets/script.js index 391bbab..f46725d 100644 --- a/assets/script.js +++ b/assets/script.js @@ -73,7 +73,7 @@ jQuery(document).ready(function ($) { /** * Handle form submission for filtering resources. */ - $('#resource-filter').on('submit', function (e) { + $('#resource-filter','#homepage-filter').on('submit', function (e) { e.preventDefault(); triggerFiltering(1); // Start at page 1 on new form submission }); diff --git a/resource-filter.php b/resource-filter.php index 3260511..10521a9 100644 --- a/resource-filter.php +++ b/resource-filter.php @@ -70,7 +70,9 @@ class ContentFilterPlugin { $post_types = isset($_POST['post_types']) ? array_map('sanitize_text_field', $_POST['post_types']) : []; $taxonomies = isset($_POST['taxonomies']) ? array_map('sanitize_text_field', $_POST['taxonomies']) : []; $posts_per_page = isset($_POST['posts_per_page']) ? intval($_POST['posts_per_page']) : 12; + $homepage_taxonomy = isset($_POST['homepage_taxonomy']) ? sanitize_text_field($_POST['homepage_taxonomy']) : ''; + update_option('content_filter_homepage_taxonomy', $homepage_taxonomy); update_option('content_filter_post_types', $post_types); update_option('content_filter_taxonomies', $taxonomies); update_option('content_filter_posts_per_page', $posts_per_page); @@ -82,6 +84,7 @@ class ContentFilterPlugin { $post_types = get_option('content_filter_post_types', []); $taxonomies = get_option('content_filter_taxonomies', []); $posts_per_page = get_option('content_filter_posts_per_page', 12); + $homepage_taxonomy = get_option('content_filter_homepage_taxonomy', ''); // Get all available post types and taxonomies $all_post_types = get_post_types(['public' => true], 'objects'); @@ -114,6 +117,18 @@ class ContentFilterPlugin {

Set the number of posts to display per page in the filter results.

+

Homepage Taxonomy

+

Select one taxonomy to include in the homepage search form.

+ +

@@ -174,7 +189,20 @@ class ContentFilterPlugin { $resTotal = $query->found_posts; // Default total resource count // Determine which form template to load - $attTmpl = ($atts['type'] === 'homepage') ? 'filter-homepage.php' : 'filter-form.php'; + if ($atts['type'] === 'homepage') { + $homepage_taxonomy = get_option('content_filter_homepage_taxonomy', ''); + + if (!empty($homepage_taxonomy) && taxonomy_exists($homepage_taxonomy)) { + $GLOBALS['homepage_taxonomy'] = $homepage_taxonomy; // Pass the taxonomy globally for the template + $attTmpl = 'filter-homepage.php'; + } else { + echo '

Error: No valid taxonomy configured for the homepage filter.

'; + return ob_get_clean(); + } + } else { + $attTmpl = 'filter-form.php'; + } + $resForm = rfGetTemplate($attTmpl); $summary = rfGetTemplate('filter-summary.php'); diff --git a/templates/filter-homepage-bak.php b/templates/filter-homepage-bak.php new file mode 100644 index 0000000..b4af00d --- /dev/null +++ b/templates/filter-homepage-bak.php @@ -0,0 +1,20 @@ + + +
+ 'resource_type']); + + if (!empty($resource_types)) : + ?> + + + + + + +
diff --git a/templates/filter-homepage.php b/templates/filter-homepage.php index b4af00d..819b75a 100644 --- a/templates/filter-homepage.php +++ b/templates/filter-homepage.php @@ -1,20 +1,35 @@ - +" method="POST"> - 'resource_type']); +$homepage_taxonomy = isset($GLOBALS['homepage_taxonomy']) ? $GLOBALS['homepage_taxonomy'] : ''; - if (!empty($resource_types)) : - ?> - +if (!empty($homepage_taxonomy)) : + $taxonomy_obj = get_taxonomy($homepage_taxonomy); + $terms = get_terms(['taxonomy' => $homepage_taxonomy, 'hide_empty' => true]); + + if (!empty($taxonomy_obj) && !empty($terms)) : ?> +
+ +
+ + + +
+ + +
+
+ labels->singular_name); ?> +
+ + + +
+
+
+
- - - - - +