Hello,
I am trying to get the posts from a logged in user.
This code displays the user that is logged in and the user id.
if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
echo 'Welcome, registered user!';
echo 'User ID: ' . $current_user->ID . "\n";
} else {
echo 'Welcome, visitor!';
};
Welcome, registered user!User ID: 1
How can I get all the posts that the user with the ID:1 has posted?
Thank you
<?php
if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
echo 'User ID: ' . $current_user->ID . "\n";
//The Query
query_posts('author=2');
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
the_title();
echo "<br>";
endwhile; else:
echo "The user has not contributed anything!";
endif;
//Reset Query
wp_reset_query();
} else {
echo 'Welcome, visitor!';
};
?>
Ok .. this is what I have so far. I have one problem here: query_posts('author=2'); How do I replace the 2 with the current user ID?
query_posts('author='.$current_user->ID );
Nevermind ... I figured it out. Had to define it in $args. :)
thanks Esmi & chinmoy29
Now if I would want to create an edit and delete link ...