[resolved] Show the logged in users thier posts. (9 posts)

  1. slevenln
    Posted 4 years ago #

    I was wondering if I can show the user (subscriber) in thier own dashboard a box with their posts. because I'm running a multiuser blog , where people register and can add posts , so I want every user to see their own posts ..

  2. duncanjbrown
    Posted 4 years ago #

    How's this for starters? Put it at the end of your functions.php file.

    See also:

    add_action( 'wp_dashboard_setup', 'display_current_user_posts_widget' );
    function display_current_user_posts_widget() {
    	wp_add_dashboard_widget( 'current-user-posts', 'Your latest posts', 'display_current_user_posts' );
    function display_current_user_posts() {
    $current_user = wp_get_current_user();
    $current_ID = $current_user->ID;
    $current_user_posts_opts = array (
    	'showposts' => 3,
    	'author' => $current_ID,
    $current_user_posts_query = new WP_Query($current_user_posts_opts);
    if ( $current_user_posts_query->have_posts() ) {
     	while ( $current_user_posts_query->have_posts() ) : $current_user_posts_query->the_post();
    	?><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title('<p>', '</p>'); ?></a>
    } else { echo "You haven't written any posts yet."; }
  3. duncanjbrown
    Posted 4 years ago #

    Sorry, that was a bit long - Pastebin

  4. slevenln
    Posted 4 years ago #

    Thank you very much duncanjbrown , but if I may ask for a favour to guide me more thru the process of putting the code in the functions.php .. cuz I found multiple files called the same "functions.php" and I'm kind of a newbie :D .. I would appreciate that very much !!

  5. duncanjbrown
    Posted 4 years ago #

    Hi slevenln. No problem. Functions.php is used to add extra functionality (like this) to a theme.

    There are two ways to get at it. Depending on your setup, you may be able to go for option 1, the internal theme editor ( Dashboard > Appearance > Editor ). Select functions.php on the right and paste the code in before the closing '?>' tag, then save.

    If you get a message saying 'these files aren't enabled for editing', you need to either fix your permissions (have a search around the forums for more details) or try option 2.

    Option 2 is to use FTP or ssh. You'll find functions.php in your /wp-content/themes/[name of your theme]/.

    If you're not sure which theme you're using, you can check at ' Dashboard > Appearance > Theme '.

    Let me know if this works for you

  6. slevenln
    Posted 4 years ago #

    Perfect !! thank you very much !! I just can't thank you enough !! :)

  7. duncanjbrown
    Posted 4 years ago #

    no problem sir :)

    This should really be a plugin, I think, with options and so on, but what you have will work in the meantime

  8. ed
    Posted 3 years ago #


    I have a situation where I want to show subscribers their posts inside of a page...the subscribers are allowed to complete their own posts but I would like to have a page that will show them all their posts or maybe a link to just their posts?

  9. duncanjbrown
    Posted 3 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic