diff --git a/README.md b/README.md index 7f98b6b..4df8028 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The Content Filter Plugin is a WordPress plugin designed to enhance content disc ## Installation -1. Clone this repo or download the plugin files and place them in the `wp-content/plugins/resource-filter` directory. +1. Clone this repo or download the [latest release](https://github.com/Vincent-Design-Inc/resource-filter/releases) and place them in the `wp-content/plugins/resource-filter` directory. 2. Log in to your WordPress admin dashboard. 3. Navigate to **Plugins** > **Installed Plugins**. 4. Activate the **Content Filter** plugin. diff --git a/assets/script.js b/assets/script.js index b3fe7c6..df12d22 100644 --- a/assets/script.js +++ b/assets/script.js @@ -28,18 +28,48 @@ jQuery(document).ready(function ($) { taxonomyFilters[taxonomy] = []; } - taxonomyFilters[taxonomy].push($(this).val()); + taxonomyFilters[taxonomy].push({ + value: $(this).val(), + text: $(this).closest('label').text().trim() // Get the text associated with the checkbox + }); }); + const toTitleCase = (phrase) => { + return phrase + .toLowerCase() + .split('_') + .map(word => word.charAt(0).toUpperCase() + word.slice(1)) + .join(' '); + }; + // Build applied filters for display + let dropdownFilters = []; + let finalFilters = {}; + for (let taxonomy in taxonomyFilters) { taxonomyFilters[taxonomy].forEach(function (term) { + let taxName = toTitleCase(taxonomy); + appliedFilters.push( - ` - ${taxonomy}: ${term} - + ` + ${taxName}: ${term.text} + ` ); + + dropdownFilters.push(term.text); + + if (!finalFilters[taxonomy]) { + finalFilters[taxonomy] = []; + } + + finalFilters[taxonomy].push( + term.value, + ); + + $(`#${taxonomy}_text`).html( + dropdownFilters ? dropdownFilters.join(', ') : taxName + ); }); } @@ -51,7 +81,7 @@ jQuery(document).ready(function ($) { search: searchTerm, paged: paged, sort_order: $('#sortOrder').val(), - ...taxonomyFilters, // Include taxonomy filters dynamically + ...finalFilters, // Include taxonomy filters dynamically }; // Perform AJAX request