How to filter $post->post_content prior to save

I have a function inside my plugin that attaches to save_post, and inside that function, I’m seeking to filter the post_content prior to it being saved. However, the content never actually gets changed once its saved. See below where I’m setting $post->post_content = “test”;

add_action('save_post', 'save_post_filter',10,2);

function save_post_filter($postID, $post){
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $postID;
    }
    else
    {
        if($parent_id = wp_is_post_revision($postID))
        {
        $postID = $parent_id;
        $post = get_post($postID);
        }
        $post->post_content = "test";
    }
}

Related posts

Leave a Reply

2 comments

  1. The ‘save_post’ filter runs after the post is filtered. If you need to modify the content before it is saved, try the ‘wp_insert_post_data’ filter.