Skip to content

Instantly share code, notes, and snippets.

@eduardobc88
Created November 16, 2016 23:02
Show Gist options
  • Select an option

  • Save eduardobc88/aeb80322fe3f4dd8b60793f84a6524d1 to your computer and use it in GitHub Desktop.

Select an option

Save eduardobc88/aeb80322fe3f4dd8b60793f84a6524d1 to your computer and use it in GitHub Desktop.
MySQL queries for WordPress
# query to get all categories
SELECT tlax_term_taxonomy.term_id as category_id, tlax_term_taxonomy.count as category_count, tlax_terms.name as category_name FROM tlax_term_taxonomy,tlax_terms WHERE tlax_term_taxonomy.taxonomy = 'category' AND tlax_term_taxonomy.count > 0 AND tlax_terms.term_id = tlax_term_taxonomy.term_id GROUP BY tlax_terms.term_id ORDER BY tlax_terms.name ASC;
# query for get post from category ID and post ID
select
b.term_id as category_id,
c.ID as post_id,
c.post_title as post_title,
c.post_content as post_content,
c.post_date as post_date,
d.meta_value as post_thumbnail_id,
e.post_name as post_thumbnail_name,
e.guid as post_thumbnail_url,
e.post_mime_type as post_thumbnail_mime_type
from tlax_term_relationships as a, tlax_term_taxonomy as b, tlax_posts as c, tlax_postmeta as d
left join tlax_posts as e
on e.ID = d.meta_value
where (a.term_taxonomy_id = 8 AND b.term_id = 8) AND ( c.post_type = 'post' AND c.post_status = 'publish' AND a.object_id = 1613 AND c.ID = 1613 ) AND (d.meta_key = '_thumbnail_id' AND d.post_id = 1613)
# query for get all posts from category ID
select
b.term_id as category_id,
c.ID as post_id,
c.post_title as post_title,
c.post_name as post_name,
c.post_content as post_content,
c.guid as post_url,
c.post_date as post_date,
d.meta_value as post_thumbnail_id,
e.post_name as post_thumbnail_name,
e.guid as post_thumbnail_url,
e.post_mime_type as post_thumbnail_mime_type
from tlax_term_relationships as a, tlax_term_taxonomy as b, tlax_posts as c, tlax_postmeta as d
left join tlax_posts as e
on e.ID = d.meta_value
where (a.term_taxonomy_id = 3 AND b.term_id = 3) AND ( c.post_type = 'post' AND c.post_status = 'publish' AND a.object_id = c.ID) AND (d.meta_key = '_thumbnail_id' AND d.post_id = c.ID) ORDER BY c.post_date DESC LIMIT 0, 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment