Jump to content

Page Searchable option


Soma
 Share

Recommended Posts

It would be good to have a settings on page to set if page is searchable.

Right now there's under "Settings" the option to "Hidden: Excluded from lists and searches" BUT what if I wanted to hide only from searches results, but still be able to use in lists $pages->find() on them if the affected pages are only used as a container.

To archive that I need to create two extra checkbox fields to all templates. "Searchable" and "Hide from Menu".

What if we would have 2 options instead:

x Hidden: Excluded from lists.

x Search: Searchable

Link to comment
Share on other sites

ProcessWire doesn't specifically know what "lists" are, so it's just using that term in a more generic sense as a "list of pages" returned by the API. Likewise, it assumes every API call is a form of "search". It just knows the API functions it provides to you, but doesn't know what you'll ultimately do with the results. That's by design, it doesn't want to start telling you where things should go. So when a page is "hidden" that means that PW is going to exclude it from any functions that return multiple pages. The most common examples would be $pages->find(), $page->find(), and $page->children(). When you call those functions, PW doesn't know if you are generating search results, building navigation, or what you are doing with them. Though if you want it to include those hidden pages in your results, you can add "include=hidden" to your selector.

The best way to achieve what you are asking about is to add your own fields, specific to your need and context. Add two checkbox fields and name them something like "is_searchable" and "is_listable" (or if more convenient, "not_searchable" and "not_listable"). Then when you use selectors to find your pages, you can specify what you want according to the context you are in. For instance, if you are generating search results, you might do something like this:

$results = $pages->find("body*=$str, is_searchable=1"); 

or if you are using a 'not' type of field:

$results = $pages->find("body*=$str, not_searchable=0"); 
Link to comment
Share on other sites

Thanks Ryan. Yes, I did it like you suggested with extra fields. I'm ok with this, only I'm thinking about: wouldn't then the "Hidden:.." settings be redundant?

Edit: Oh yes, thanks for pointing out the include=hidden, forgot about that, wich solves part of the issue.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...