Forums

[resolved] How to find if user has made a post before? (5 posts)

  1. 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.

  2. totalGraybear
    Member
    Posted 2 years ago #

    anyone...

  3. totalGraybear
    Member
    Posted 2 years ago #

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

  4. MichaelH
    moderator
    Posted 2 years ago #

  5. 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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags