show my posts only
this will give a shortcode where logged in users will see only their posts
function show_only_my_posts_shortcode() { // Check if the user is logged in if (is_user_logged_in()) { $current_user = wp_get_current_user(); $args = array( 'author' => $current_user->ID, 'post_type' => 'post', 'posts_per_page' => -1, ); $query = new WP_Query($args); // Check if there are posts to display if ($query->have_posts()) { $output = '<ul>'; while ($query->have_posts()) { $query->the_post(); $output .= '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>'; } $output .= '</ul>'; } else { $output = '<p>No posts found.</p>'; } wp_reset_postdata(); } else { $output = '<p>Please log in to view your posts.</p>'; } return $output; } add_shortcode('my_posts', 'show_only_my_posts_shortcode');