Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-09-29 23:11:50

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 241
Website

Exluding articles from search results if custom field is something

I have a website where a custom field is used to specify if a company has seized to exist. So when a person is searching for companies, those articles that have a value in a specific custom field, should not show in the search results. Can this be done? The custom field is named Closed (Y) and if the field has a value Y then it shouldn’t show in the search.

Offline

#2 2013-09-30 08:08:22

etc
Developer
Registered: 2010-11-11
Posts: 5,397
Website GitHub

Re: Exluding articles from search results if custom field is something

The simplest way is to hide things, wrapping the content of your search_results form in if_custom_field, but this breaks pagination:

<txp:if_custom_field name="Closed" value="Y">
<txp:else />
<!-- search results content -->
</txp:if_custom_field>

Using a “closed” section excluded from search results would be a cleaner solution.

Offline

#3 2013-09-30 08:35:07

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 241
Website

Re: Exluding articles from search results if custom field is something

Alright, thanks for the code tip. :-) That works just fine, I think. In this case I won’t be changing sections for the closed business articles as that would change the URL structure.

Offline

#4 2013-09-30 08:58:36

etc
Developer
Registered: 2010-11-11
Posts: 5,397
Website GitHub

Re: Exluding articles from search results if custom field is something

Then I would increase the value of limit attribute in the “search” part of page form, to avoid half-empty search pages:

<txp:if_search>
<txp:article limit="9999" />
<txp:else />
...
</txp:if_search>

Edit: but probably <txp:article Closed="" /> will do the job just fine?

OT for Jukka: the match attribute of if_custom_field accepts a potentially unsafe regexp pattern match type.

Last edited by etc (2013-09-30 09:44:04)

Offline

Board footer

Powered by FluxBB