Forums

show one users posts only (4 posts)

  1. bellbottombabe
    Member
    Posted 5 years ago #

    hi,

    This is probably an easy query (unless u don't know of course) so presuming that u guys do ....

    I need to show only the posts associated with the current user who is logged in i.e. when user logs in they see a list of THEIR POSTS preferably within a link to 'edit this post'. I guess a, 'get_posts_by_username' type tag would be useful if one existed - or a plugin.

    Thats all really -- any ideas please???

  2. Otto
    Tech Ninja
    Posted 5 years ago #

    query_posts("author_name=YOUR USER NAME") at the beginning of your loop will do it.

    http://codex.wordpress.org/Template_Tags/query_posts

    http://codex.wordpress.org/The_Loop

  3. bellbottombabe
    Member
    Posted 5 years ago #

    hi, thanks for ur quick reply -

    to clarify,
    [1]
    do you mean place this within the loop (first line inside the loop) or completely outside the loop.

    [2]
    what variable do i pass into this function in place of, "YOUR USER NAME" - since i can't specify it literally (i.e. it must be derived from the user that is currently logged in)

    [3]
    I'm using my own loop since i'm using my own static home.php page will this still work in this situation - i've copied most of the main template tags to it such as header(), sidebar() etc....

  4. Otto
    Tech Ninja
    Posted 5 years ago #

    1. Just before the loop. Not inside it.
    2. Probably better to use the author=ID# instead. Then you just need to check $user and $user->ID to see who's logged in. if ($user) { query_posts('author='.$user->ID); }, basically.
    3. Should work okay. Depends on how your custom loop works.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags