I want to exclude a SINGLE collection item from search. Please advise on how I can do this.
Here is my site Read-Only: LINK
(how to share your site Read-Only link)
I want to exclude a SINGLE collection item from search. Please advise on how I can do this.
Here is my site Read-Only: LINK
(how to share your site Read-Only link)
I’m afraid that’s not possible.
Go to CMS collection pages > site search setting. Enable the option “exclude these from site search pages” by mentioning the collection search title.
Hi Vectra,
Just found this, as i had the same issue. Better late than never, but you can hide it with the following JavaScript:
</body>
<script>
jQuery(document).ready(function() {
jQuery('.search-result-items a[href^="search-hide"]').each(function() {
jQuery(this).parent().hide()
});
})
</script>
search-result-items
as a class on your search list. Not the wrapper.search-hide
inside the slug of the item you wish to hide.Voila.
Just had a client request this without needing to change slugs to avoid SEO stuff and 301 redirecting.
Here is an approach that can be used with a CMS field instead of the slug incase anyone has the same request.
</body>
// Get all elements with data-search="toggle"
const toggleElements = document.querySelectorAll('[data-search="toggle"]');
// Iterate through each toggle element
toggleElements.forEach(toggleElement => {
const innerHTML = toggleElement.innerHTML.trim();
// Check if innerHTML starts with "hidden"
if (innerHTML.startsWith("hidden")) {
// Find the closest parent element with data-search="result"
const resultParent = toggleElement.closest('[data-search="result"]');
// Set the display style to "none" if a result parent element is found
if (resultParent) {
resultParent.style.display = "none";
}
}
});
Add the data-search=“result” to the result item on the search results page:
Add the data-search=“toggle” to a text element in the result item that is bound to the search description:
Create a dropdown field in the CMS collection and give it an option of “hidden”:
Add the CMS field into the CMS collections Template Search settings "Search Description field: