Created
October 14, 2013 21:30
-
-
Save minio/6982551 to your computer and use it in GitHub Desktop.
query to get all posts and associated categories from Wordpress database
This file contains 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
$all_posts = $wpdb->get_results(" | |
SELECT wp_posts.ID,wp_posts.post_date,wp_posts.post_title,wp_posts.post_name, | |
wp_terms.name,wp_terms.slug,wp_term_taxonomy.description | |
from wp_posts | |
join wp_term_relationships on wp_posts.ID = wp_term_relationships.object_id | |
join wp_terms on wp_term_relationships.term_taxonomy_id = wp_terms.term_id | |
join wp_term_taxonomy on wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id | |
WHERE wp_posts.post_status = 'publish' | |
ORDER BY wp_terms.slug,wp_posts.ID; | |
", ARRAY_A); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment