I think this is what you are looking for:
function my_posts_shortcode_wpse_135655() {
if (!is_user_logged_in()) return;
global $current_user;
get_currentuserinfo();
if (!empty($current_user->ID)) {
$userp = new WP_Query(
array(
'post_author' => $current_user->ID,
)
);
$content="";
if ($userp->have_posts()) {
while ($userp->have_posts()) {
$userp->the_post();
$content .= get_the_title();
}
} else {
$content .= "You don't have any posts.";
}
wp_reset_postdata();
return $content;
}
}
add_shortcode('my_posts','my_posts_shortcode_wpse_135655');
Stepping through it:
- Do nothing if the user is not logged in
- Else retrieve the user data for the logged in user
- If we have user data run query to get the user posts
- Output the titles of those posts
- Reset post data
To use this shortcode, just add [my_posts /]
to any post or page.