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!


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

$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 '<a href="'.$site.'blog/article/'.$row['post_name'].'/'.$row['ID'].'/">'.$row['post_title'].'</a>';
}
  • Share/Save/Bookmark

Related posts:

  1. Get Articles from a specific cagetory in Wordpress After googling and not found any code, I made my...
  2. Wordpress get_page() function Well this is the first time that I am having...

Tags: , ,

One Response to “Get Posts from Wordpress to an External Page”

  1. overnight cialis Says:

    Yes I agree with you!

Leave a Reply