Forum Moderators: coopster

Message Too Old, No Replies

Current User ID

         

almo136

8:14 pm on Jun 19, 2009 (gmt 0)

10+ Year Member



In wordpress I have this piece of PHP which shows all the posts from the author with the id of 1:

<?php
$numposts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_author = 1");
echo "Posts by .....";
foreach ($numposts as $numpost) {
echo "<ul><li>".$numpost->post_title."</li></ul>";
}
?>

Instead of showing the posts of author 1 I would like to show the posts of whoever is currently logged on.
I have this other bit of code which shows how to find out the id of the current user:

<a href="http://mysite.com/?author='. wp_get_current_user()->ID . '">Category</a>

I tried replacing the 1 in the first statement with
'. wp_get_current_user()->ID . '

But that just gave me an error.

Any ideas how I can fix this?

Thanks.

mooger35

9:13 pm on Jun 19, 2009 (gmt 0)

10+ Year Member



give this a try

$numposts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_author = ". wp_get_current_user()->ID);

or

$userid = wp_get_current_user()->ID;
$numposts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_author = $userid");

almo136

9:55 pm on Jun 19, 2009 (gmt 0)

10+ Year Member



The first line worked perfectly.

I now have a list of the posts but no links. Do you know how I would add links to the posts?

Thanks!