• Resolved totalgraybear

    (@totalgraybear)


    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter totalgraybear

    (@totalgraybear)

    anyone…

    Thread Starter totalgraybear

    (@totalgraybear)

    hmmm…most of my questions end up unanswered…must be my looks…

    Thread Starter totalgraybear

    (@totalgraybear)

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to find if user has made a post before?’ is closed to new replies.