Skip to content

Instantly share code, notes, and snippets.

@loorlab
Created November 8, 2024 15:15
Show Gist options
  • Save loorlab/75da53de72815f65b8acac7a7cbf8079 to your computer and use it in GitHub Desktop.
Save loorlab/75da53de72815f65b8acac7a7cbf8079 to your computer and use it in GitHub Desktop.
Query - MySQL - WordPress | Total Posts by category
SELECT
COUNT(p.ID) AS total_contenidos
FROM
wp_posts p
JOIN
wp_term_relationships tr ON p.ID = tr.object_id
JOIN
wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
JOIN
wp_terms t ON tt.term_id = t.term_id
WHERE
p.post_status = 'publish'
AND p.post_type = 'post'
AND tt.taxonomy = 'category'
AND t.slug = 'leer-es-mi-cuento';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment