Show history of post revisions on front end
I'm working on an internal knowledgebase and I want to show the post history on the front end (with something like author, date and difference).
I first landed on wp_get_post_revision()
(https://developer.wordpress.org/reference/functions/wp_get_post_revision/) and after more searching I found wp_list_post_revisions()
(https://developer.wordpress.org/reference/functions/wp_list_post_revisions/) which looks closer to what I want.
However, while messing with this I'm running into errors while updating posts (Updating failed. The response is not a valid JSON response.) and I don't see anything on the front end when I return the shortcode. I was hoping there was a plugin for this but since I cannot find one I'm creating a quick one. What am I doing wrong and what's the best way to accomplish this?
Here is what I've tried:
function history_shortcode() {
//global $wpdb;
//$revisions = $wpdb-get_results(select * from {$wpdb-posts} where post_parent={$post_id} and post_type='revision');
$revisions = wp_list_post_revisions(get_the_ID());
return $revisions;
}
add_shortcode( 'history', 'history_shortcode' );