Understanding Wordpress database schema - querying from 3rd party app
Posted
by deceze
on Stack Overflow
See other posts from Stack Overflow
or by deceze
Published on 2010-05-14T02:34:23Z
Indexed on
2010/05/14
2:44 UTC
Read the original article
Hit count: 267
Wordpress
Is there an easy way to grab the latest posts out of a Wordpress wp_posts
table using a simple SQL query?
I have a Wordpress 2.9.2 installation as part of, but separate from, a larger system. It has a customized theme to look like the rest of the site but has otherwise nothing to do with it. I want to display the latest handful of headlines of posts made using Wordpress on a site of that other system. Preferably I do not want to mess around with importing any of the Wordpress library files.
Looking at the database structure I can't see an easy, straight-forward query to simply get the latest revision of the latest posts. The post_status
can either be "post" or "inherit", the post_type
"post" or "revision" and the parent "0" or the id of the original post of a revision. I can't figure out how to reliably filter different revisions of the same post, drafts, attachments and pages out of this mess and just get the latest revision of the latest posts.
I'm aware that the database schema is subject to change in subsequent versions of Wordpress, so shouldn't be relied upon, but that's a minor concern, since it's such a minor feature that could easily be fixed. If I understood how that database is supposed to work, that is.
© Stack Overflow or respective owner