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
$revisions = wp_get_post_revisions( $post_id );
if ( $revisions ) {
foreach ( $revisions as $revision ) {
// Do something with each revision, such as display the revision ID
echo 'Revision ID: ' . $revision->ID . '
';
}
} else {
echo 'No revisions found for this post.';
}
// Example 2: Limit the number of revisions to retrieve
$revisions = wp_get_post_revisions( $post_id, array( 'number' => 5 ) );
if ( $revisions ) {
foreach ( $revisions as $revision ) {
// Display limited number of revisions
echo 'Revision ID: ' . $revision->ID . '
';
}
} else {
echo 'No revisions found for this post.';
}
// Example 3: Retrieve revisions for a specific post type
$revisions = wp_get_post_revisions( $post_id );
if ( $revisions ) {
foreach ( $revisions as $revision ) {
// Check if the revision is for a specific post type
if ( get_post_type( $revision->ID ) === 'custom_post_type' ) {
echo 'Revision ID: ' . $revision->ID . '
';
}
}
} else {
echo 'No revisions found for this post type.';
}