I’m looking to retrieve the most recently published post in a wordpress system. I have some basic mysql understanding and I can find where the revisions are stored in the wp_posts table but what I can’t seem to find is how to retrieve the permalink for the most recent post.
any ideas on how to retrieve the most recent post with mysql and permalink?
I see there are some existing functions from WP like so:
// get the latest blog entry
$myposts = get_posts('numberposts=1');
foreach($myposts as $post) :
echo '<a href="' . the_permalink() . '">' . the_title() . '</a>';
endforeach;
But when I put this on a custom page I’m working on, it seems to just be pulling out the page name I’m currently on and the link to this page (even though I’m thinking the above function should be retrieving a ‘post’.
What am I missing?
Just in case you may want to have a real MySQL solution, here’s what I use:
now the $post array holds all the data regarding to the latest post.
Worked out the solution: