• Hey,

    I hope this is something that would be simple. Is there a way for text/button to be visible to only the author of a post.

    What I mean is if “user a” creates a post, there would be button included in his post that only he can see. The button would be a submit button for an edit form that will add a text to the title of a post and close comments. This button I would like only for the user of the post and admin to see, is there a way to do this.

    I would imagine it would be something to do with the_author tag and if and echo statement.

    OI apologize the elaborate question/explanation, but any help would be appreciated, thanks.

Viewing 1 replies (of 1 total)
  • Use get_currentuserinfo() to get the ID of the user viewing the page. Then inside the loop check that ID against $post->post_author. Echo your button if it matches. It should look something like:

    global $current_user;
    get_currentuserinfo();
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    /// post stuff
    if ($post->post_author == $current_user->ID) echo $button;
    /// post stuff
    endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
Viewing 1 replies (of 1 total)
  • The topic ‘PHP “button that only author of post can see”’ is closed to new replies.