views:

36

answers:

2

I have this code wich gets WP posts, but it gets all the posts and orders them from the first to the last. I want only the last 10 post ordered from last to the earlier. What I have to change? Thanks a lot in advance!

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = 'myblog';
mysql_select_db($dbname);

$result = mysql_query("SELECT * FROM wp_posts WHERE post_type = 'post'")



while($row = mysql_fetch_array($result))
{
echo $row['post_date'] . " " . $row['post_content'] . " " $row['post_title'];
echo "<br />";
}


?>
+1  A: 

Change your query...

SELECT * FROM wp_posts WHERE post_type = 'post' ORDER BY past_date DESC LIMIT 10;

Which orders posts from the newest to the oldest, limiting the results to only 10 rows.

Urda
+3  A: 

SELECT * FROM wp_posts WHERE post_type = 'post' ORDER BY post_date DESC LIMIT 10

mathroc