• Edit: This is for the Widget Logic plugin. Not sure why it didn’t post to that plugin’s forum.

    Just wanted to share this as an example for others who might be struggling with complex exclusionary logical statements. Could be a good example to add to the notes. Sorry if this was already mentioned.

    I wanted to display widgets on all posts and pages EXCEPT for single posts in a certain category. I figured the following would work:

    !is_single() && !in_category(‘category’)

    However, this excluded the widgets not only from single posts in “category,” but from all other single posts. It seemed like the AND operator was behaving as an OR operator. I tried enclosing the whole statement in parentheses, but it didn’t change anything. It took me a while to figure out that this unexpected result was because of the ! modifier.

    The proper syntax for this statement is:

    !(is_single() && in_category(‘category’))

    This will display widgets for everything except single posts in the category named “category.”

    Hope this is helpful to someone else, so that tearing my hair out was worth it. 😀

  • The topic ‘[Widget Logic] How to use complex exclusionary conditions (with the ! modifier).’ is closed to new replies.