Random WordPress Function

Learn about a new WordPress function every day!


Function Signature:

wp_get_post_revisions

Function Description:

Returns all revisions of specified post.

Function Examples:

⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Example 1: Retrieve all revisions for a specific post
$post_id = 123;
$revisions = wp_get_post_revisions( $post_id );
if ( $revisions ) {
    foreach ( $revisions as $revision ) {
        echo 'Revision ID: ' . $revision->ID . ', Revision Date: ' . $revision->post_modified . '
'; } } else { echo 'No revisions found for post ID ' . $post_id; }
// Example 2: Get the latest revision for a post
$post_id = 456;
$latest_revision = wp_get_post_revisions( $post_id, array( 'order' => 'DESC', 'posts_per_page' => 1 ) );
if ( $latest_revision ) {
    echo 'Latest Revision ID: ' . $latest_revision[0]->ID . ', Revision Date: ' . $latest_revision[0]->post_modified;
} else {
    echo 'No revisions found for post ID ' . $post_id;
}
// Example 3: Check if a post has revisions before retrieving them
$post_id = 789;
$revisions = wp_get_post_revisions( $post_id );
if ( $revisions ) {
    foreach ( $revisions as $revision ) {
        // Process revisions
    }
} else {
    echo 'No revisions found for post ID ' . $post_id;
}