totalGraybear
Member
Posted 2 years ago #
I am customizing a template. In it, I need to check if the currently logged in user has made any previous post. Just a Yes/No (or the number of posts if it is easier).
I tried this:
while ( have_posts() ) : the_post();
if (the_author('login',FALSE)==$loggedinusername){
$postcounter=the_author_posts();
}
endwhile;
But all I get is the repeated display of the # of posts (in the displayed page) made by the logged-in user.
The variable $postcounter returns nil.
There must be an easier way to do this...
Please help.
totalGraybear
Member
Posted 2 years ago #
totalGraybear
Member
Posted 2 years ago #
hmmm...most of my questions end up unanswered...must be my looks...
totalGraybear
Member
Posted 2 years ago #
Next time, I'll show up in drag, may be that'll help :))
It did work, Thanks very much MichaelH. Here's what I did:
if (have_posts()) : while (have_posts()) :the_post();
if (get_the_author()==$username){
$postcounter=get_the_author_posts();
}
endwhile;
endif;
if((int)$postcounter>0) {
blah blah blah
}
I had to put the counting statement inside an IF statement to avoid echoing authorname or # of posts.
Also, it appears that get_the_author_posts() returns a string value. I had to convert it to an integer before I could use it. It shouldn't be that way, may be I wasn't doing something right.