Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-10-04 15:52:27

Myusername
Member
Registered: 2019-12-12
Posts: 162

Search for multiple values in a custom field?

I’m working on a search page where I need to display some articles filtered by custom fields. It turns out that, from the tests I did the <txp:article/> tag sees the custom field as a string, so that even if I have a custom_field called “cms” with the value “Wordpress, Textpattern”, it will only return me if the search is for “Wordpress, Textpattern”.

<txp:article cms="Wordpress">
    nothing
</txp:article>

<txp:article cms="Textpattern">
    nothing
</txp:article>

<txp:article cms="Textpattern, Wordpress">
    nothing
</txp:article>

<txp:article cms="Wordpress, Textpattern">
    Something here
</txp:article>

Any way to get around this?

Last edited by Myusername (2020-10-04 15:52:45)

Offline

#2 2020-10-04 18:27:18

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

Re: Search for multiple values in a custom field?

Myusername wrote #326222:

Any way to get around this?

The only way I can currently think of, is cheat:

<txp:php>
    $_GET['cms'] = array('%Textpattern%', '%Wordpress%');
</txp:php>

<txp:article_custom match="cms=cms">
    <txp:title />
</txp:article_custom>

Offline

#3 2020-10-05 01:32:31

Myusername
Member
Registered: 2019-12-12
Posts: 162

Re: Search for multiple values in a custom field?

Yes, it works. Thank you so much for your help. -I’m just starting my career in programming, the forum and txp have helped me a lot. I’m really grateful .

Are there any thoughts for the future about custom fields working as arrays?(I believe that is the point). Something like the keywords field already does.

Offline

#4 2020-10-05 08:25:13

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

Re: Search for multiple values in a custom field?

Myusername wrote #326224:

Yes, it works. Thank you so much for your help. -I’m just starting my career in programming, the forum and txp have helped me a lot. I’m really grateful .

You are welcome, glad you find the forum helpful and thanks for your interest and contribution.

Are there any thoughts for the future about custom fields working as arrays?(I believe that is the point). Something like the keywords field already does.

Yes, a past proposal here and a future one there. It’s taking shape, but we are a small team permanently distracted by new ideas, php upgrades and other time-consuming stuff.

Note that you can already search for multiple values via URL:

<!-- access this page via ?cms[]=%Textpattern%&cms[]=%Wordpress% URL -->

<txp:article match="cms">
    <txp:title />
</txp:article>

Offline

Board footer

Powered by FluxBB