Filtering the loop based on one custom field value OR another

Hi guys,

Probably a simple one but I can’t seem to work it out from the docs, I have a loop

 <If loop exists type="wcrm_ticket_activity" custom_field=wcrm_tickets_activity_ticketid custom_field_value="{Field id}" custom_field_2=wcrm_ticket_category custom_field_value_2="update" orderby=date order=desc>

I also want to filter by ‘audit’ as well as by custom_field_value_2=“update”

I feel it is going to use the any_is operator but can’t find the documentation.

Thanks in advance, I’ve been scratching my head too long on this.


Great question, I’m genuinely surprised that I don’t think this use case has actually come up, there doesn’t seem like an easy way to achieve this. I think this is probably just a limitation of filtering with query parameters where you can’t get fancy with logic. You can filter your query based on up to three custom field values using query parameters like custom_field_value_2 and custom_field_value_3, but it doesn’t seem like that gives you a way to say “show me results that have this value OR this value OR this value.”

When you’re filtering a loop based on multiple taxonomy terms, there’s a parameter called taxonomy_relation that you can set to and or or, but it doesn’t seem like there’s an equivalent like custom_field_relation to achieve what you’re trying to do here. I’ll pass that along as a feature request. If that’s not possible, I’m sure we should at least be able to set up a field_relation attribute for the loop tag. Maybe both.

I think the current solution to this would involve first stacking several If statements (maybe using a logic variable since that might be more compact) while setting any=true. Then if that logic variable is true, you could just create a basic type=wcrm_ticket_activity loop and then within the loop, filter it based on multiple conditions (again, maybe through another logic variable).

This seems oddly hacky though, so I’ll pass this by someone more experienced on the team to see if I’m just not caffeinated enough yet and I’m missing something obvious. If not, I’ll be sure to create a feature request since this is definitely the kind of thing that L&L should be able to accomplish more easily.

Thanks very much @benjamin , I did find it rather odd, my solution for the time being was to add a secondary category ACF as I was trying to display all with ‘update’ which included an ‘audit’ then on a different tab only an ‘audit’ which worked with 2 categories but it would definitely be nice to be able to use and OR statement of some kind in the future.



1 Like