WordPress.org

Ready to get started?Download WordPress

Forums

Creating custom tag plugin question (2 posts)

  1. hepaestus
    Member
    Posted 9 years ago #

    I have a custom tag plugin that I am writing and I want it to directly edit the post in the database. I want this to happen when the post is created and whenever it is edited.

    This way once you use the custom tag the results are saved in the post and the tag disapears leaving the reformatted text.

    I have surmised that I need to run the plugin as an action like so:

    add_action('edit_post', 'function_name');
    add_action('edit_post', 'function_name');
    add_action('publish_post', 'function_name');
    add_action('publish_post', 'function_name');

    The issue is that the publish_post and edit_post hooks return the post id. What is the best way to access the content of the database for the post? Is there a global database connection object I can use to run my query against? How is it best used for backwards compatibility?

    Thanks,
    Pete

  2. TechGnome
    Moderator
    Posted 9 years ago #

    When ever I've needed to get at the post, I use the post_id and run a query to return the posting. Then I modify it, and execute another query to update the data back again.

    Another option is to use the filter for "format_to_post" or "the_content" they get passed in the content of the post itself. Now, these happen right before the content is displayed, and so the changes would not be saved. This may or maynot be preferable - but just think about what you would like to have happen if you, say deactivated or deleted the plugin.

    Tg

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.