Support » Plugins » Recent Posts hack broken by images in wp_posts

  • Resolved chiquita


    On my blog at I’ve been using a really bad, hacky way to pull out my last 3 posts at the bottom of my page.

    I searched for a plugin to do this, but I could never find one. So I hacked one together using my really basic knowledge of PHP and MySQL.

    It wasn’t pretty, but it worked pretty effectively until I upgraded to 2.0 and uploaded images.

    Because Images now get stored in the wp_posts table all my crappy script is pulling out is the last three images I uploaded.

    I can see that I could filter out the images by using the post_staus field, but my lack of PHP knowledge means I’m not sure how to do it.

    At the moment my code is like this:

    $query="SELECT * FROM wp_posts ORDER BY post_date DESC";
    $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
    $num = mysql_num_rows($result);
    $limit = "4";

    if ($num>$limit) {

    if ($num > 0) {

    $i = 0;
    while ($i < $to) {


    $limit = "200";
    $post_length = strlen($post_content);

    How/where would I add a bit that says:

    if post_status = attatchment then goto next record?

    Or am I barking up the complete wrong tree?

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’ve worked it out now, I just needed to change the first line to

    $query="SELECT * FROM wp_posts WHERE post_status='publish' ORDER BY post_date DESC";

    Wouldn’t it be easier to just use the proper template tag? It’s certainly a lot LESS lines of code–

    <?php wp_get_archives('type=postbypost&limit=10'); ?>

    This tag just pulls post titles, but I’m sure it can be altered to pull the posts.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Recent Posts hack broken by images in wp_posts’ is closed to new replies.