Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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
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
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