Reputation: 40187
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";
}
Upvotes: 0
Views: 257
Reputation: 816790
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
Upvotes: 0
Reputation: 51160
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";
}
Upvotes: 0
Reputation: 15935
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.
Upvotes: 4
Reputation: 401142
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 :
"/%postname%/"
"/%postname%/"
"/%postname%.html"
"/%postname%.html"
Upvotes: 4
Reputation: 6660
Yes, switch them to AND
and it should work. You could instead reverse those to ==
and put a !
in the front.
Upvotes: 0