I’m trying to display some content based on a post author in WordPress. Here is the code I’m trying inside the loop
<?php
$author = the_author_meta('first_name');
echo $author;
if ($author == "Rabin" ) {
echo 'hi rabin';
}
else {
echo 'not Rabin';
}
?>
But unfortunately this is not working. Every page/post is giving the same result. I’ve put it after this lines
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
I have placed echo $author; for testing and it is echoing the author’s name but the rest if else function is not working.
Any help would be great. Thanks in advance..
Use “get_the_author_meta” not “the_author_meta”.
the_author_meta one only displays it and cannot be used to be assigned to a variable:
http://codex.wordpress.org/Function_Reference/get_the_author_meta