Advertising
Paste Description for Wordpres Mysql cheat-sheet
Handy queries. Not as trivial as one would think :) http://wordpress.org/support/topic/242658
Tested on Wordpress 2.7.1
- Wordpres Mysql cheat-sheet
- Saturday, February 21st, 2009 at 4:27:11am MST
- /* All posts of category 'recipes' */
- SELECT id,post_title
- FROM wp_term_taxonomy
- JOIN wp_terms
- ON wp_term_taxonomy.term_id = wp_terms.term_id
- JOIN wp_term_relationships
- ON wp_term_taxonomy.term_taxonomy_id
- = wp_term_relationships.term_taxonomy_id
- JOIN wp_posts
- ON wp_term_relationships.object_id = wp_posts.id
- WHERE wp_term_taxonomy.taxonomy='category' AND name='recipes'
- AND post_type='post' AND post_status='publish'
- ORDER BY id DESC
- /* all tags and number of posts for each (tag cloud) */
- SELECT wp_terms.name,
- count(wp_term_relationships.object_id) AS num_posts
- FROM wp_term_taxonomy
- JOIN wp_terms
- ON wp_term_taxonomy.term_id = wp_terms.term_id
- JOIN wp_term_relationships
- ON wp_term_taxonomy.term_taxonomy_id
- = wp_term_relationships.term_taxonomy_id
- JOIN wp_posts
- ON wp_term_relationships.object_id = wp_posts.id
- WHERE wp_term_taxonomy.taxonomy='post_tag'
- AND post_type='post'
- AND post_status='publish'
- GROUP BY wp_terms.term_id
- ORDER BY name ASC
- /* All posts of with tag 'spicy' */
- SELECT id,post_title
- FROM wp_term_taxonomy
- JOIN wp_terms
- ON wp_term_taxonomy.term_id = wp_terms.term_id
- JOIN wp_term_relationships
- ON wp_term_taxonomy.term_taxonomy_id
- = wp_term_relationships.term_taxonomy_id
- JOIN wp_posts
- ON wp_term_relationships.object_id = wp_posts.id
- WHERE wp_term_taxonomy.taxonomy='post_tag' AND name='spicy'
- AND post_type='post' AND post_status='publish'
- ORDER BY id DESC
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.