Get Posts from Wordpress to an External Page

Below will get the All articles from Wordpress Database to an external file and display in random order.Also, it depends on how you customized your “Permalink Structure”. Sample below has “/article/%postname%/%post_id%/”. I am using the same code on my footer!

[sourcecode language='php']

//////////////////////////////////////////////////////////////////////

$conn = mysql_connect(‘localhost’,'root’,”);
mysql_select_db(“keithics”,$conn) or die(mysql_error());

if (!$conn) {
die(‘Error!!–> ‘ . mysql_error()); // if there’s an error, e.g. wrong password or username.
}

$sql = “Select * from `wp_posts` where post_status = ‘publish’ order by rand() limit 5 “;

$result = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_array($result))
{
echo ‘‘.$row['post_title'].’‘;
}

[/sourcecode]

2 Responses to “Get Posts from Wordpress to an External Page”

  1. Yes I agree with you!

  2. nagaraju says:

    i am studying final year i am doing project for that i can utalise your coding and i feel very happy

Leave a Reply