Get Articles from a specific cagetory in Wordpress
After googling and not found any code, I made my own script to get articles from wordpress with a specific category.
Category = term_taxonomy_id // you can see it in the database table called wp_term_taxonomy
Here is the code:
//////////////////////////////////////////////////////////////////////
$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 wp_posts.* ,wp_term_relationships.* from `wp_posts`,`wp_term_relationships` where wp_posts.post_status = 'publish' and wp_term_relationships.term_taxonomy_id = 7 and wp_posts.ID = wp_term_relationships.object_id 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>';
}
Related posts:
- Get Posts from Wordpress to an External Page Below will get the All articles from Wordpress Database to...
- Wordpress get_page() function Well this is the first time that I am having...
Tags: Freelancing, PHP programming, Wordpress
