WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Show only MY posts in the loop if I'm a logged in user (3 posts)

  1. ElaineMarley86
    Member
    Posted 1 year ago #

    I'd like to have on my blog a page which shows to the logged in user only the posts of the logged in user.
    Explanation: I'm user Charlie Brown, I log in, I want to see only postst of the author Charlie Brown (i.e. myself) inside this page.
    How can I write this loop?

    Thanks everyone!

  2. vtxyzzy
    Member
    Posted 1 year ago #

    Get the current user id (zero if not logged in) and add the 'author' argument to the query.

    If you want to keep all previous arguments, use this:

    $id = get_current_user_id();
    if ($id) {
       global $wp_query;
       query_posts(
          array_merge(
             $wp_query->query,
             array('author' => $id)
          )
       );
    }

    Otherwise, just create your own argument array for the query.

  3. ElaineMarley86
    Member
    Posted 1 year ago #

    Thanks, it works perfectly!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags