How to display wordpress post of a specific category on an external php page?
0.o Mastermind ^_^’ asked:
I am working on a website, but one of the requirements is that i have is to be able to show announcements on a separate page. I am running the Xoops CMS, and being familiar with Wordpress i got the Xoops Wordpress module which is exactly the same only it allows the post to be displayed within the xoops cms. I decide that rather than manually updating the announcements page i would use wordpress and only display post from the announcements category. Using code from the first example on this website http://www.roccanet.com/blog/tutorial/tutorial-integrating-wordpress-2-blog-to-an-existing-site-with-cache/
i was able to get the wordpress post on an external php file. Unfortunately it displays all of the post from all categories. What i need is to display post from just my announcements category (i.e. category_id = 7 ). Although i am familiar with PHP programming, the MySQL/PHP part of it is something i am now getting into. All help with this would appreciated and i thank you in advance.
| Digg |
Stumble
|
Sphinn |
Del.icio.us
|




This should do it. Just set r.term_taxonomy_id below to be the category number you want pulled.
SELECT p.*
FROM wp_posts AS p
LEFT JOIN wp_term_relationships AS r
ON p.ID = r.object_id
WHERE r.term_taxonomy_id = 7
AND r.object_id IS NOT NULL
ORDER BY p.ID DESC