tags:

views:

84

answers:

6

I've created this code branch so that if the permalink settings do no match at least one of the OR conditions, I can execute the "do something" branch. However, I believe there is a flaw in the logic, since I've set permalinks to /%postname%.html and it still tries echo's true;

I believe I need to change the ORs to AND, right?

if (get_option('permalink_structure') !== "/%postname%/" || 
          get_option('my_permalinks') !== "/%postname%/" || 
    get_option('permalink_structure') !== "/%postname%.html" || 
          get_option('my_permalinks') !== "/%postname%.html"))
{
//do something
    echo "true";
}
A: 

Yes, switch them to AND and it should work. You could instead reverse those to == and put a ! in the front.

St. John Johnson
+4  A: 

You are testing :

if(get_option('permalink_structure') !== "/%postname%/"

And your permalink is /%postname%.html -- which means it is not "/%postname%/"

So, that first portion of the condition is true, and you are entering into the if block -- and the other ones are not even evaluated.


I suppose what you want is to use &&, and not || :

if(get_option('permalink_structure') !== "/%postname%/" 
    && get_option('my_permalinks') !=="/%postname%/" 
    && get_option('permalink_structure') !== "/%postname%.html"
    && get_option('my_permalinks') !=="/%postname%.html"))
{
//do something
    echo "true";
}

Which would mean :

  • if permalink is not "/%postname%/"
  • and permalink is not "/%postname%/"
  • and permalink is not "/%postname%.html"
  • and permalink is not "/%postname%.html"
  • then, echo true
Pascal MARTIN
+4  A: 

when you do a construct like this:

 if($a != 1 || $a != 2)

then it will always be true since for this to be false $a should be 1 and 2 simultaneously.

your construct is similarly flawed.

Toad
A: 

Use ands, not ors. Have made the same mistake myself.

Kevin
A: 
if !(get_option('permalink_structure') == "/%postname%/" || 
           get_option('my_permalinks') == "/%postname%/" || 
     get_option('permalink_structure') == "/%postname%.html" || 
           get_option('my_permalinks') == "/%postname%.html"))
{
    echo "true";
}
Joe Philllips
This is valid syntax?
Felix Kling
A: 

As the other say, use AND (&&) instead of OR (||). If you are unfamiliar with Boolean logic, here in short:

TRUE and FALSE == FALSE
TRUE and TRUE == TRUE

FALSE or FALSE == FALSE
TRUE or FALSE == TRUE
Felix Kling