Skip to content

Instantly share code, notes, and snippets.

@zoranzaric
Created December 5, 2009 11:03
Show Gist options
  • Save zoranzaric/249647 to your computer and use it in GitHub Desktop.
Save zoranzaric/249647 to your computer and use it in GitHub Desktop.
Some usefull SQL-Querys for Wordpress
#get all published posts with their tags and categorys
SELECT *
FROM wp_posts
LEFT JOIN wp_term_relationships
ON wp_posts.ID=wp_term_relationships.object_id
LEFT JOIN wp_terms
ON wp_term_relationships.term_taxonomy_id=wp_terms.term_id
WHERE post_status='publish';
#get all published posts for a given tag-id or category-id
SELECT *
FROM wp_posts
LEFT JOIN wp_term_relationships
ON wp_posts.ID=wp_term_relationships.object_id
WHERE post_status='publish'
AND wp_term_relationships.term_taxonomy_id=1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment