Forums › Forums › Search & Filter Pro › Hide heading if empty results
Tagged: Heading Hide Taxonomy Title
- This topic has 4 replies, 2 voices, and was last updated 1 year, 10 months ago by Anonymous.
-
Trevor(Private) February 25, 2018 at 6:51 am #161894
Each Tag/Category/Taxonomy/Post Meta form UI element has two options:
Display Count and Hide Empty. If you want to hide the term when the count is 0, then select @Hide Empty’ AND, in the General Settings, set both Auto Count setting to ON.
Then, you will need to write some custom javascript to trigger on page load and when the form or form controls change and to check if the controls have some or no child options, and if they do, to hide or reveal them.
Anonymous(Private) July 29, 2022 at 5:07 pm #276627The following css solution does not YET work (July 2022), but it should be viable once browsers begin implementing css Selectors Level 4. It requires the :has pseudo class, and also requires that the :empty pseudo class ignores whitespace.
`css
.searchandfilter>ul>li:has(>ul:empty) {
display: none;
}
`
https://caniuse.com/css-has
https://caniuse.com/mdn-css_selectors_empty_matches_whitespaceAnonymous(Private) July 29, 2022 at 5:28 pm #276628Here is a JS solution. This is a little crude, but it works. Obviously this would need run after the DOM is ready.
// test if there is a searchandfilter form on the page
if (document.querySelector(‘.searchandfilter’)) {// query all the ul elements within our filters
const filters = document.querySelectorAll(
‘.searchandfilter > ul > li > ul’
);// hide the parent (li) element for any that are empty
filters.forEach((filter) => {
if (filter.children.length === 0) {
filter.parentElement.style.display = ‘none’;
}
});
} -
AuthorPosts