Created
March 7, 2015 18:00
-
-
Save rendfall/7d8e03e32db8df635661 to your computer and use it in GitHub Desktop.
[WordPress] Get Posts with meta
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getPostsWithMeta() { | |
| global $wpdb; | |
| $query = " | |
| SELECT DISTINCT | |
| ID, | |
| post_title, | |
| post_date, | |
| guid | |
| FROM wp_posts | |
| LEFT JOIN wp_postmeta v1 ON (wp_posts.ID = v1.post_id) | |
| LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) | |
| LEFT JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) | |
| LEFT JOIN wp_terms ON (wp_term_taxonomy.term_id = wp_terms.term_id) | |
| WHERE 1=1 | |
| AND wp_posts.post_status = 'publish' | |
| AND wp_posts.post_type = 'page' | |
| AND wp_posts.post_parent = 30 | |
| ORDER BY wp_posts.post_date DESC | |
| "; | |
| return $wpdb->get_results($query); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment