2

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?

2
  • 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
1

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.

2
  • 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 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.