Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need a 3 part conditional statement with all negatives but I can't get it to work. I need to say that the post isnt in category 'videos' or its child categories and isn't from the author with the id of 3. This is what I had but obviously doesn't do the trick.

if (!in_category('videos') || !post_is_in_descendant_category(9) && !is_author('3'))
share|improve this question

closed as off topic by kaiser, Stephen Harris, m0r7if3r, toscho Apr 15 '12 at 22:40

Questions on WordPress Development Stack Exchange are expected to relate to WordPress within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Plain PHP syntax questions are on topic on Stack Overflow. –  toscho Apr 15 '12 at 22:40
    
wordpress conditional statements aren't a wordpress question? I was only able to get my problem solved because mor7if3r knew the correct conditional tag for the author. Bizarre. I think some of you just like to do that. –  Pollux Khafra Apr 15 '12 at 22:59
    
It doesn't matter for your question if you use is_string() or is_author(). It is just about syntax, not about the checked value. Feel free to discuss it on meta. –  toscho Apr 15 '12 at 23:02
    
blehhh whatever –  Pollux Khafra Apr 15 '12 at 23:08

2 Answers 2

up vote 2 down vote accepted

I like to split this kind of thing to more than one conditional, as it makes it easier for me to read.

if( !( in_category( 'videos' ) || post_is_in_descendant_category( 9 ) ) ) {
    if( get_the_author_meta( 'ID' ) != 3 ) {
    }
}

Given, it's a bit more code, but that's the way it reads best to my eyes.

share|improve this answer
    
yeah I see your point but this also isn't applying the condition. It works fine in the opposite way if I take out the negatives so are you not allowed to use more than one? –  Pollux Khafra Apr 15 '12 at 19:40
    
I have no idea what you mean by "Applying the condition", you can use as many negatives as you want as far as PHP is concerned. –  m0r7if3r Apr 15 '12 at 19:49
    
Sorry Im still learning the correct terminology. What I mean is that the element is still being shown even though it's told not to by the negative conditional tags. It still shows for all the posts with author "3" and I've triple checked to make sure all the details are correct. –  Pollux Khafra Apr 15 '12 at 20:20
    
Oh wow...can't believe I missed that. It's because is_author() checks for an author archive page. What you want to is use get_the_author_meta() and use that in your conditional. I've updated my answer. –  m0r7if3r Apr 15 '12 at 20:28
    
Eureka! I wasn't the clearest about what I was using it for and I'm gonna work on that. Thanks for helping me out! –  Pollux Khafra Apr 15 '12 at 21:12
if (
    ( ! in_category( 'videos' ) OR ! post_is_in_descendant_category( 9 ) )
    AND ! is_author('3')
)
    // do stuff

That reads:

if :
    [ NOT in cat Name "Videos" = TRUE -- OR -- NOT post is in desc cat Nr. 9 = TRUE ]
    AND NOT is author with ID 9 = TRUE
// do stuff
share|improve this answer
    
that returned a syntax error Im guessing because of the extra ) after the second conditional statement and when I removed it, none of the statements applied to the element. –  Pollux Khafra Apr 15 '12 at 19:22
    
You're right. One ) too much. See update. –  kaiser Apr 15 '12 at 20:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.