• Dear All,

    I have written a plugin that builds a table of content from the data in my blog posts using content filters. Unfortunately, it does not play well with posts that are split in pages (using <!–nextpage–>) because the filter does not see the full content of the post, but only the page being currently served. As a result, I get a different (crippled) table of content on each page of the article, matching only the displayed content.

    How can my filter access the full content of the post (I guess WordPress has to load it in full?). If that’s not possible, how can I load it from the database from my plugin ?

    Thanks for your help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Try using get_post_field(). The default context parameter may not work, but one of the others, such as ‘raw’ should get what you need.

    Thread Starter Esikad

    (@esikad)

    Thank you very much for your reply. Reading the WP source code, I found that global $pages; could work. Is there something wrong with this approach? Are there situation where it could fail?

    Moderator bcworkz

    (@bcworkz)

    That would work fine for now. You also see suggested hacks all over the place that use the global $post as well. Using such globals is convenient, and in some cases may be the only alternative. Doing so still strikes me as being a bit fragile. WP developers may change the way these globals are used at some point in a way that breaks code using them.

    I prefer to use dedicated functions when possible. If the use of globals should change at some point, I would expect the developers to alter the dedicated functions accordingly to avoid breaking plugins and themes, or at least give adequate warning through a deprecation process. We cannot expect such courtesy when using global values meant for internal use.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Accessing full post for split content’ is closed to new replies.