WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] exlusions are ignored when combined

[Resolved] exlusions are ignored when combined

  • This is an issue I’ve had for several version sof WordPress. I’m always doing workarounds to handle it, but it seems to me that it *should* work like this. Maybe I’m missing something.

    as an example, if I use:

    if(! is_search() || ! is_404())

    in a template file (doesn’t have to be the above – it can be if(! is_home() || ! is_front_page()) or if(! is_category() || ! is_archive()) – any combination of using more than on item with the “!” and || together) the statement is completley ignored.

    if(! is_search()) works fine on it’s own, as does if(! is_404()). but putting them together, separated by a “||”, it’s ignored on both pages.

    Is this a bug? Or is there something I’m missing in regards to how PHP works?

Viewing 5 replies - 1 through 5 (of 5 total)
  • I don’t think you’ll ever get if(! is_search() || ! is_404()) to return false.

    The same with everything above that you’ve listed. You don’t have a PHP problem, or a WordPress problem; you have a logic problem.

    Can you explain – in human terms, not in conditional logic – what you’re trying to accomplish with if(! is_search() || ! is_404())?

    that’s funny… it’s seems logical *to me* LOL

    ETA: if I use if (is_search() || is_404()) I can make stuff appear on those two pages. So I guess I don’t get why the addition of the “!” makes it “illogical.” Does that make sense?

    I don’t want the sidebar to show up on the search results page or the 404 page.

    I realize I could just do a search.php and 404.php template file, but since the layout is exactly the same as the index.php file, sans sidebar, I just wanted to use a conditional to not pull it in.

    The problem is with the logic. The codes you are currently using are saying something like:

    If this isn’t the search page or this isn’t the 404 page.

    When you’re visiting the 404 page, that’s more than likely not the search page, so your code is going to return true. If you’re visiting the search page, that’s most likely not the 404 page, so the code is going to return true. If you’re visiting the home page, that’s not the 404 page and it’s not the search page, so the code will still return true.

    If you are looking to exclude something from the 404 page and the search page, you need to use the and operator, not the or operator. Therefore, in order to exclude something from the 404 page and the search page, you would use:

    if( !is_search() && !is_404() )

    ::smacks head::

    NOW you’re making sense. I’m having a total DUH moment here. Thank you for pointing out my silliness! I appreciate it 🙂

    Curtiss beat me to the punch. 🙂

    Glad you got it resolved!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] exlusions are ignored when combined’ is closed to new replies.
Skip to toolbar