Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1

I need the pages tag to provide all cloned pages that have varying specific properties (in custom field).

I have an input form where I set the desired properties. First I have date from and date to fields. These I compare against a field on every page (date). No problems so far, however, now I have a bunch of multiselect inputs, like status can be "ok, denied, okbyteamleader" and a field "requesttype" that can be a ton of things like "plus time", "minus time", "vacancy", "sick", "meeting" and several more.

So what I want to do is to get all pages between date from and date to where the corresponding fields on each page contain any of the values selected (like all pages where the date field is between 2017-11-20 and 2017-12-12 and where the status field value is either "ok or "okbyteamleader" and where the requesttype field is either "plus time" or "minus time".

I hope you can understand what I want to do.

Anyway, I already asked about a boolean or operator for the custom_field function once and I know it doesn't exist, and that I could use cms:query to build my own query, but before I do that (as it seems to be a very daunting task) I wanted to ask: Could I compare a custom field against an array somehow, so it checks for all the values inside the given array? That would make life a lot easier and still wouldn't require an OR operator for custom_field.

Also, as a side question, is there an easy way to put a a php array (like from a $_POST variable into a couch array?

Best regards.
When using the custom_field parameter, using a single '=' is akin to using LIKE '%%' in SQL. That means that in theory you could have an 'or' scenario.

Code: Select all
<cms:pages masterpage='blog.php' custom_fields="statusfield=ok,okbyteamleader|requesttype=plus time, minus time"  start_on='2017-11-20' stop_before='2017-12-12'>

EDIT : Trendoman is right though, this only allows for an OR within each field. I think this is what you mean but if you are looking for a scenario whereby you want pages that match the requesttype OR match the statusfield then you will need to use Trendoman's solution and use the <cms:query> tag.
Let's repeat the docs ... stom_field :)

custom_field="statusfield=ok,okbyteamleader|requesttype=plus time, minus time"

In the given sample there will be fetched pages with boolean logic: ( %ok% || %okbyteamleader% ) && ( %plus time% || %minus time% ). So a page to be selected must have both editable fields filled (means AND && ), each with either one value (means OR ||). Sign % means a LIKE comparison - first field's value could start with 'ok', for example (as in 'okay'). Following change asks for exact value: statusfield==ok,okbyteamleader|requesttype==plus time, minus time.

Currently CouchCMS doesn't support (within given cms:pages tag) fetching pages where some field1 has certain value OR field2 has certain value - so in this sense there is some limitation. It means that the solution would be to fetch all pages with required constraints on field1, then all pages with constraints on field2 and then combine both lists together to remove duplicates. It can be done with some php array or new couchcms's multi-value variables. It is also advisable to create one query that instructs the SQL database to do both searches at once (and there is nothing complicated there).

Anyway, to see things in action it is very comfortable to use return_sql='1' parameter of cms:pages. With it, the tag would output only the resulting sql query, which can be copy-pasted, tweaked up to your liking and used in cms:query tag.

P.S. Parameter name is custom_field, not custom_fields - please fix the typo in your post :)

thanks a lot for the help. I fixed the typo ;)

I have used a workaround for if field1 = x OR field2 = y before (using multipe page tags, fetching only the id's of each query, then using a php array to combine the id list and then grab the resulting pages proper).

However, I did not realise that I can just comma seperate values in the custom_field to get the desired OR operation within a single field. Actually I'm pretty sure I tried it and it didn't work, but I realise now it was because not all fields provided data.

I got it working as intended now, thanks a lot :)
4 posts Page 1 of 1

Who is online

In total there are 4 users online :: 0 registered, 0 hidden and 4 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 4 guests