• I’m having an issue with if statement in wordpress. Is it possible to put in 3 conditions in a statement? It works with two just fine.

    if ($output1 == “” && $output2 == “” && $output3 == “”){
    do something
    }

    I”m getting an error with this. Please let me know your thoughts.

Viewing 8 replies - 1 through 8 (of 8 total)
  • That is a php programming question but yes, it’s fine to do that.

    Thread Starter paulsvang

    (@paulsvang)

    Shannon,

    The problem is that it’s not working in the latest version of WP. I’m not sure why. The only thing I can think of is the plugin I’m using.

    To find out why it’s not working, you jsut need to do some simple de-bugging.

    Add this line above your if() statment, and it will show you what the values are so you’ll be able to see which one/ones are breaking the conditions

    echo "<p>Output 1: '".$output1."', Output 2: '".$output2."',Output 3: '".$output3."'</p>";

    Thread Starter paulsvang

    (@paulsvang)

    I’ve done that. That’s why I’m confused.

    Output1 = “”
    Output2 = “”
    Output3 = “value”

    The problem is that when I put in a third condition, and submit the form, then it’s in a loading phase and never goes anywhere. If I change to two conditions, it works just fine.

    Base on the condition above, when all variables are empty, then the “do something” will take place however Output3 has a value in it so it should pass over the condition and continue on with the rest of the code. It’s just not making any sense to me right now. I’m using the plugin “Insert PHP” so that I can use PHP code within the page text area… I’m wondering if this is causing the issue.

    • This reply was modified 8 years, 5 months ago by paulsvang.

    What do you mean by “never goes anywhere”?

    From what you’ve jsut said it sounds like the code inside the loop is being executed even though there is a value set that would make one of the arguments false. Is that right?

    I haven’t used the ‘Inter PHP’ plugin before as I really don’t like the idea of clients playing around with that. If it was me, I’d extract whatever you’re trying to do there into a shortcode. That way the code is out of the way and can’t be “broken” by anyone else trying to edit the page.

    Thread Starter paulsvang

    (@paulsvang)

    i figured out the issue. It was passing the condition to the next but there was an issue on the next condition. Fixed it. Thanks all for your input. It was user error.

    @paulsvang,

    Kindly change the status to ‘resolved’.

    Thread Starter paulsvang

    (@paulsvang)

    Just changed. Thank you for the reminder Maria.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘PHP If statement with 3 Conditions’ is closed to new replies.