WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom meta box which I would like to use to report on the markup of the current post or page (number of words, number of heading tags, etc).

How can I obtain the post content into memory in order to parse and report on its content inside the meta box?

share|improve this question
Do you want the post as it was loaded into the editor (via the global $post variable), or do you want it client-side and update it there too? The word counter under the editor does that by reading $('#content').val(). – Jan Fabry Oct 28 '10 at 5:48
Yes, I just need the post content as it was when loaded into the editor. I need to pass a keyword to a function that parses through the content to find the existence of the keyword in h1, h2 and h3 tags. – Scott B Oct 28 '10 at 12:04
up vote 1 down vote accepted

The callback for a meta box gets the current object (post, comment, link, ... depending on what you're editing) passed as the first parameter. So in your meta box handler you can read this first argument and access it's post_content to get the content.

share|improve this answer
Thanks Jan. That was it. Any suggestions on how to parse the content and report on its markup? eg, given a keyword or keyword phrase that's assigned to the post, report on whether the keyword appears in a h1, h2, h3 tag? – Scott B Oct 28 '10 at 15:36
@Scott: The only reliable way of parsing HTML is with the DOM. If it only is a limited number of tags, you could search for them and check whether their text content contains your keyword. If you want to find all keywords with their context I think you have to use XPath. – Jan Fabry Oct 28 '10 at 17:57

Your Answer


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.