WordPress Notes

Collection of code fragments and useful notes for WordPress

Basic word-count by post, from databse

SELECT `ID`, `post_date`, `post_name`, `post_type`, `post_status`, `post_title`, `guid`, SUM( LENGTH(`post_content`) - LENGTH(REPLACE(`post_content`, ' ', '')) + 1 ) AS 'Wordcount' 
FROM `wp_posts` GROUP BY `ID` HAVING `post_type` = 'post' 
AND `post_status` = 'publish' 
ORDER BY `Wordcount` DESC LIMIT 0, 10000

Get list of WP posts with coauthors, including date

If you use Coauthors Plus plugin and need a list of posts. This provides basics, including the slug of the Coauthor slug.

SELECT name, post_title, post_name 
FROM wp_term_taxonomy AS c_term_taxonomy
INNER JOIN wp_terms AS c_terms ON c_term_taxonomy.term_id = c_terms.term_id
INNER JOIN wp_term_relationships AS c_term_relationships ON c_term_taxonomy.term_taxonomy_id = c_term_relationships.term_taxonomy_id
INNER JOIN wp_posts AS c_posts ON c_term_relationships.object_id = c_posts.ID
INNER JOIN wp_postmeta AS meta ON c_posts.ID = meta.post_id
WHERE c_posts.post_status = 'publish'
AND c_posts.post_date >= "2021-01-01"
AND c_posts.post_type = 'post' 
AND c_term_taxonomy.taxonomy = 'author'
GROUP BY name, post_title
ORDER BY name, post_title;