WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] IF IS post author/editor show content - ELSE hide (3 posts)

  1. Philip
    Member
    Posted 3 years ago #

    hi to community,

    i have twirl my brain all day to find how i can show a button or something else inside a loop (single.php) if the logged in user is the author of the post.

    i have try all the conditional tags in the documentation...but with no luck...

    now i try this:

    <?php
    global $current_user;
    get_currentuserinfo();
    if (is_user_logged_in() && (current_user_can('edit_posts') || $current_user->ID == $post->post_author) ) {
    echo 'button or something';
    }
    ?>

    but with this every logged in member can see the "button or something",

    does anyone know how i can do this?

    thanks a lot,
    Philip

  2. Philip
    Member
    Posted 3 years ago #

    ok, i found what i need/you need to do for this....

    first step:
    need to get the ID of the user viewing the page

    second step:
    need to check the ID against $post->post_author and echo some content

    so how to compile this:
    1. before the loop get the ID of the user viewing the page

    <?php
    global $current_user;
    get_currentuserinfo();
    ?>

    2. inside your loop check the ID against $post->post_author

    <?php
    if ($post->post_author == $current_user->ID)
    echo 'AUTHOR CONTENT HERE';
    ?>

    i know a lot of people searching a solution for this, hope you enjoy it...:)

    love you WordPress,
    all the best!!!

    Philip

  3. Profusion
    Member
    Posted 2 years ago #

    Great Post

    Just what I needed - thanks

Topic Closed

This topic has been closed to new replies.

About this Topic