I have a custom post type called species which consists of a number of meta_fields.

Ideally, what I'd like, is a word count for each species profile (that's just the term I use for a singular post of type species).

So, for example, when you click the Species menu in the back-end, you can see a list of all the species profiles (paginated, as WordPress does) with information about how many words are in each species profile and to be able to sort by that ASC/DESC.

If I was doing this outside of the back-end area I'd probably do the following:

  • Retrieve all of the data for the specific Post_ID
  • strip_tags the data (and WP's shortcode tags)
  • Put it all in a big string
  • Use $array = explode( " ", $string ) to create a large array
  • Get the word count from sizeof( $array )

Question is, how can I put this into the WordPress admin area for this post type? And how do I make it sortable?

Thanks in advance,


I think your best bet is to hook save_post and save the count for each post to a meta field. It's not feasible to do the calculation when the back end is loaded, every post will have to be queried and sorted in memory. Likewise, doing it all in MySQL will require some significant query modification, and still then you won't be able to remove shortcodes and markup from the numbers.

as far as the columns and sort are concerned, there are several answers here on how to do that, start with the Related questions column to the right. Also see this post by Scribu on the subject.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.