Properly showing posts of currently logged in users
-
Hi All,
I have this code to show the posts of the current logged in user with a button to edit each post via the front end.
This works great, but if the person is not logged in, all that shows is my header and my footer, but blank content. I would like to add a message that asks the users to log in to edit their posts. Can you please help me with that?
Thanks!
Here is the code:
function logged_in_author_posts(){ if ( is_user_logged_in()){ echo 'Please log in to edit your posts.'; }else if( !is_user_logged_in()) return false(); $user_id = get_current_user_id(); $postIDno = get_the_ID(); $mylink = site_url(); query_posts( array( 'post_type' => 'directory', 'author' => $user_id, 'post_status' => 'publish', 'showposts' => '-1' )); if( have_posts()): echo '<h2>Your Listings</h2>'; echo '<ul>'; while (have_posts()) : the_post(); global $post; echo '<li>'; the_title(); the_excerpt(); echo '<form method="get" action="edit-listings">'; echo '<input type="submit" id="submitBtn" class="button gform_next_button" value="Edit" tabindex="20">'; echo '<input type="hidden" name="gform_post_id" value="'.$post->ID.'" />'; echo '</form>'; echo '</li>'; endwhile; else: echo '</ul>'; endif; }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Properly showing posts of currently logged in users’ is closed to new replies.