To list the logged in author’s posts and put an edit link after each title, you can use the following function:
function logged_in_author_posts(){
if( ! is_user_logged_in() )
return false;
$query = new WP_Query( array(
'post_type' => 'post',
'author' => get_current_user_id(),
'post_status' => 'publish',
'posts_per_page' => -1
));
if( $query->have_posts() ):
echo '<h2>Your posts</h2>';
echo '<ul>';
while ( $query->have_posts() ) : $query->the_post();
echo '<li>';
the_title();
edit_post_link( __('Edit'), ' <span>', '</span>' );
// the_excerpt();
echo '</li>';
endwhile;
echo '</ul>';
wp_reset_postdata();
endif;
}
You can take out the double-slash ‘//’ from // the_excerpt(); to show the post excerpt.
Note: we use a new WP_Query instance here instead of the old query_posts() function, as query_posts() modifies the main query and is discouraged. wp_reset_postdata() restores the global post data after our custom loop.
Now you can use logged_in_author_posts() anywhere in your theme to display the list. The list will only appear if the user is logged in and has at least one published post.
logged_in_author_posts();
