NO BUG: Having to still use AND instead of OR for conditions?

Browser: Chrome 110
OS: macOS / Windows / Linux / etc.
URL: Link to a page that illustrates this issue
Video: Short screen recording that illustrates this issue (free tool: jam.dev)

[Please describe this bug in as much detail as possible so we can replicate & debug this bug]

When using page conditions to show/hide templates/sections in pages based on conditions, AND is having to be used to get a variety of conditions to work - when it should be OR?

I think this has been reported before and been said to be fixed, but for me, I still have to keep using AND in order to get conditions that are each separate (OR) to work.

i.e Querying a post type, page ID, or ACF like in this screenshot:

These things are all separate conditions and not ones that need to all be true/false. It also makes it really hard to then create groups of AND conditions mixed in (i.e If post type is Events and not and archive page).

Click a plus button on tab heading, not on condition element

I know where the OR option is, my post is about the fact it doesn’t work? If the options are set to OR, they don’t work. I am having to still use AND instead of OR for conditions to work.

It does oddly work for some instances, but the example I shared was in the header section of the website - so not sure if that’s related.

Hey Rob,

not exactly sure what you’re referring to here. Your screenshot is showing element conditions, isn’t it?

Best,

André

Sorry André you’re absolutely right, I was referring to element conditions in this instance. I’m not sure if PC do the same thing, so I’ll update my post to correct phrasing.

No problem. :slight_smile: So you’re saying that the OR operator does not correctly work for element conditions?

That’s correct! For instance if I change the last condition there to say OR, i.e If it is JUST of the post type Events, the element will show again on pages with that post type.

As soon as I change it to AND, it works.

It’s also the same for the Post ID rule, where Post/Page ID 2 will still show this element unless I set it to AND.

I set up a quick test (not the exact same conditions as you’re using as I’m not sure about your exact setup) and for me it seems to work correctly:

1 Like

Really odd Andre, but you’re right.

I can give you logins if it helps, I’ve just tried it again to hide a template (I am using templates mostly pulled into pages, with conditions on those) and if I set it to AND, it’s hidden, but OR, and it shows:

it’s possible you’re misunderstanding the conditions. (difficult to tell as we don’t know what that echo function and dynamic tag are returning) we’d need a simplified example without custom functions.

However, in your video, that header part will be showing because the first lot of conditions is returning TRUE. Everything up to the OR.

And the second part, ‘OR the post isn’t post 902’ becomes irrelevant, because the first part was TRUE. And adding the OR means it doesn’t need the second part to be true, only for one of them to be true. So whatever you add in the next bit won’t matter if the first part is already true.

You might be right there dude, but the conditions definitely don’t all apply or removing the last rule would mean the third rule of isn’t post ID would not show before I add it, right? But it does :confused:

If you can describe when you want the element to display (which of the conditions should be true), I can tell you how to add it in).

Most of the time with negative conditions, AND is needed, not OR. Example - only show when the post ID isn’t 9 AND isn’t 11.

1 Like

Appreciate it.

Did you see my video dude? Basically all those conditions I wanted isolated, they don’t need to group up.

I had the same issue in reverse, as I mentioned above, where I did want things to be AND - but they were treated like OR as I found in my first video.

Either I’m drastically misunderstanding the use case here or we’re talking at cross purposes and my install for whatever reason is not behaving as expected. Thing is, it’s been the same on other fresh installs I’ve had too :confused:

I don’t know what you mean by isolated.

They can only be set up be ALL true (meaning you use AND between each one), or they can be set up so ANY can be true (meaning you use OR between them).

We can’t see from your video which is true or false, as you’re using custom functions. So we don’t know which are returning true and which aren’t for that post (apart from the post IDs one).

If you can give that info or simplify the example so it doesn’t include those unknowns, it’ll be easily solved.

My guess is that AND is actually correct for what you’re trying to do, because the conditions are negatives (is empty, isn’t post ID, isn’t Events) and so using OR would be incorrect and would just show the element the moment that one of them is true (which would be pretty much every page).

Yes you’re 100% on the mark with your last statement. By isolated I mean, on their own (OR) and not grouped (AND). The echo was for an ACF field tick box in the backend, if it’s ticked, hide it (again as an OR, I don’t want these conditions combined as AND).

You can see towards the end of the video, I set an OR condition to not include that post ID I was viewing there, as a demo, but it still showed. I then set it to AND, and it disappears. So surely that means if the other things were still valid, the OR would just be ignored and it wouldn’t show - it was the addition of the AND rule at the end that made it hidden.

Again, sorry if I’m missing something there.

So to describe it, based on this image:

I am looking for conditions to SHOW this element, being:

IF the boolean field (tick box) is not ticked

OR

If the post ID is NOT 2

OR

The post title type of that post is NOT Events

OR

The post ID is not 123


Does that make sense? It’s currently working, like I say, with AND, pretty much how I expected that to be. But surely I need to be using OR?

You’re getting mixed up with the negatives.

But surely I need to be using OR?

No, AND is correct for this (because of the negatives). If it was OR, then the element would show for every post.

Think about it… if you have it as OR… then it means ANY of those conditions can be true for the element to show.

If we simplify your example, and only include the post ID conditions… every single post on your site will be EITHER post ID is NOT 2 OR post ID is not 123. (including post 123 and post 2, because they both aren’t each other)

But to have it so every post apart from 2 and 123 (which is what you’re trying to do) it needs to be both not 2 AND not 123.

Hmm, yeah I kinda see what you’re meaning and you’re right, I understand what I’m trying to do but maybe it’s the negatives?

I guess if I used ORs but with positives, it would be a bit of a different story.

I think my understanding of OR is flawed in that case, as I assumed it just meant if any of these conditions apply, it’s not shown. The AND seemed to me to mean that all of those things had to be true at once, if that makes sense? (i.e the Post ID had to not be 2 AND 123 at the same time.)

Appreciate your help clarifying though, so you’re saying keep using AND in this instance?

Yep, AND is correct for your example. The simple way to remember it is that it flips from OR to AND for negatives).

OR is … “if any of the conditions are true, it’s shown”
AND is… “if all of the conditions are true, it’s shown”

Quick example of why it flips for negative (hopefully makes it more clear)…

Imagine 6 posts, A,B,C,D,E,F. We want a banner to display on D,E & F.

We could do the positive…

  • Post is D OR E OR F.

Or the negative…

  • Post isn’t A AND it isn’t B AND isn’t C.

Both will show the element only for D,E,F.

If we did it wrong, and tried to use OR for the negative…

  • Post isn’t A OR it isn’t B OR isn’t C.

it would show on every post, because on each post one of those things would always be true.

2 Likes

Yeah that’s a real headscrew, but I do see what you mean.

I still struggle a little bit with the AND logic I must admit, haha, but I do see that.