Finding the length of WordPress Posts

I’m just finished converting my plugin pages to use my new WP README Parser plugin. However, I had a nagging feeling that I might have missed, at the very least, 1. But how can I easily tell without going through them all one-by-one?

Well, their length is a give-away as instead of pages of text, there’s now a single call to my plugin. A quick bit of SQL will show the length of each post and/or page in characters, allowing me to see if any of the original versions still exist.

Here is an example using standard table naming and will list the details of pages…

SELECT ID, post_title, guid, length(post_content) AS 'Post Length'
  FROM `wp_posts`
 WHERE post_type = 'page'
   AND post_status <> 'draft'
   AND post_status <> 'trash'
 ORDER BY length(post_content)

That 3rd line can be modified to WHERE post_type = 'post' for posts, or combined with the original to list both posts and pages.

Otherwise, it simply lists the ID, title and URL for each page as well as the character length of the page content. It excludes drafts and anything in the trash. The final list is sequenced by the length of the page.

Not sure if this is useful to anyone, but just in case….!

Talk to me!

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from David Artiss

Subscribe now to keep reading and get access to the full archive.

Continue reading