Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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,

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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