I'm writing a plugin for WordPress that dynamically generates content from a Google Documents Spreadsheet. Specifically, the plugin provides a shortcode that generates a good-looking staff list. It works, but there are two problems:

  1. Pages that use the shortcode load a little slow, because they have to make multiple requests to another server
  2. Since the content is generated when the page is loaded, the contents of the staff list do not show up in search results on the site

I can fix the first problem with some level of caching, but what can I do about the second problem? I mention the first problem because I think the ideal solution is one in which WordPress indexes the cached copy of the page.

Another solution I can think of would be to have the content of the page composed by a plugin periodically. That way the page could be searched and wouldn't be dynamically generated every time. However, it seems like a strange paradigm for a plugin to completely control the content of a page...are there other plugins that do this? Also, this approach exposes complexity to the user that it shouldn't have to. (They'd have to edit the contents of the page from a plugin page instead of the normal place.)

Here's a sample of what part of the markup for the page looks like:

<h2>General Management</h2>

[staff-directory department="General Management"]

The spreadsheet to hit is configured separately. The "department" specifies the worksheet. (I'd show you what the results look like, but I don't have enough rep to post an image.)

Your suggestions are greatly appreciated.

2 Answers 2


The wp_posts table has a post_content_filtered column that plugins can use to cache expensive post content filters. The idea is that when you display the page, you don't read post_content but you read post_content_filtered. This is nice, but it won't solve your search problem because WordPress by default only looks at post_content and post_title.

You can however do it the other way around: store the editor content in post_content_filtered and the rendered page in post_content (update it periodically with a cron job). There are filters that are called before the post is edited, you can use them to pass post_content_filtered instead of post_content to the editor. So the user will see no difference, but the performance and the search experience will be improved.

  • Awesome. I really don't like having to use those tables backwards from their intention, but I think that's the cleanest solution on the table right now.
    – Doug Paul
    Commented Apr 6, 2011 at 23:46
  • Actually, if I end up installing a plugin for caching, could that nullify or severely complicate this approach? Are caching plugins responsible for generating post_content_filtered, and/or do they host pages from that table?
    – Doug Paul
    Commented Apr 7, 2011 at 0:10
  • @Doug: I am not sure, but I think the classic cache plugins don't use this field, because they cache more than individual posts (also archive pages and so). I assume they store the generated HTML output as files in a cache directory and read them from there. But you can just try it out in a test environment: install a cache plugin, visit the site, and see whether post_content_filtered gets used.
    – Jan Fabry
    Commented Apr 7, 2011 at 5:50

I see two ways

If speed is important, than caching would solve both of your problems. If you can somehow add a timestamp of last modification to the cache and the data retrieval url/get, with a simple hash algorythm you can be sure, that the cached version is up to date.

If speed is not so relevant, you can use the API to ask for the spreadsheet. For example, you may not need PHP, instead you can use JavaScript and JSON for a very quick search, like the data retrieving in this example.

In your place, I'd stick with caching the data, calculating if Google Docs is not available at the very moment of the search query.

  • Speed isn't a huge factor, but it's important enough that I can't hit the spreadsheet everytime a visitor performs a search (I think this is what you're saying in your second suggestion.) As for your first suggestion, how does caching solve both problems? Where do I "cache" such that the cached version gets searched?
    – Doug Paul
    Commented Apr 6, 2011 at 23:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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