Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-02-28 10:55:30

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

Filter articles by their custom fields

What’s the best way to realize an advanced articles filtering system?
I can filter article in section using a cf.
I generate URL like this:

http://www.domain.com/section/?custom_field_name="foo"

Using smd_if I check in urlvars if cf is defined and publish an article_custom

<txp:smf_if valeu="urlvar:custom_field_name" operator="isdefine">
<txp:article_custom custom_field_name="{smd_if_custom_field_name}" />
<txp:smd_if>  

But how concatenate? How add or remove var (custom fields)?

Offline

#2 2012-02-28 11:56:38

Zanza
Plugin Author
Registered: 2005-08-18
Posts: 699
Website

Re: Filter articles by their custom fields

Could this thread be of any use? It inspired me to build up this site section (dropdown by year mixed with categories menu). Lot of conditionals at work. :)

Offline

#3 2012-02-29 10:46:33

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

Re: Filter articles by their custom fields

HI Zanza,
I’ve created a system like yours for Toscana Guide
It can go deep one level. After article_custom can’t do more…
Maybe smd_query?!

What do you think?

Offline

#4 2012-02-29 13:19:38

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: Filter articles by their custom fields

If you need a more complex setup, smd_query will help you. Use the query attribute and write your own SQL statement (as in example 2 or example 3 except with the textpattern table instead of the category table in the examples – if you’re not sure what your query should be, make a relevant query with txp:article_custom and look at the tag trace in debugging mode to see the SQL query it produces, then work from there). The basic principle is to capture the url variables and turn them each into variables that each consist of an AND line of the query. You can then build up your SQL query out of a series of successive txp:variables.

Important: Take care to filter any user-input data before allowing it to be passed to the query. txp:php or rah_function with doSlash or doSpecial or a relevant php function will help.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB