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'))
  • Plain PHP syntax questions are on topic on Stack Overflow. – fuxia 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. – fuxia Apr 15 '12 at 23:02
  • blehhh whatever – Pollux Khafra Apr 15 '12 at 23:08
  • Why is this "offtopic" here but if you ask a php question and mention wordpress then it is also offtopic there? – JGallardo Sep 18 '17 at 17:30

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.

| 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. – mor7ifer 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. – mor7ifer 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
| 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.