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 function that returns true when the author is an admin or an editor or of a certain role.

I can't use is_single because I have set up a forum and there are a million singles out there and I need a different layout for THE posts (the ones written in the blog by admins and editors) than from the forum entries

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

author_can() seems to fit.

Example:

if( author_can( get_the_ID(), 'administrator' ) ) 
share|improve this answer
    
Yes it does, thanks a lot! –  Lisandro Dec 11 '10 at 22:01
    
Could you give me an example of how to use it? Thanks –  Lisandro Dec 11 '10 at 22:06
    
Added example. I think docs cover function quite well, anything in particular you have trouble with? –  Rarst Dec 11 '10 at 22:16
    
Thanks, I tried it and it worked. I have just one question, how do I add a second role so that it triggers then too? like for example editor. –  Lisandro Dec 11 '10 at 23:37
    
Make two checks and join them with PHP or operator - ||. This is more of PHP basics than WP. –  Rarst Dec 11 '10 at 23:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.