Recent Posts hack broken by images in wp_posts
-
On my blog at http://www.escapecrate.co.uk 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) {
$to=$limit;
}else{
$to=$num;
}
if ($num > 0) {$i = 0;
while ($i < $to) {$post_title=mysql_result($result,$i,"post_title");
$post_content=mysql_result($result,$i,"post_content");
$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?
The topic ‘Recent Posts hack broken by images in wp_posts’ is closed to new replies.