1

Some wordpress post has many revisions, and I know how to list all revisions,use code:wp_list_post_revisions( int|WP_Post $post_id, string $type = 'all' )

However, How to list only the authors of every revision in the post, need to meet:

  1. list the author of all revisions;
  2. the author does not repeat;(Maybe the author edited the same post several times)
  3. The author has a link to his profile page

thank you very very much!

2 Answers 2

0

Use Can Use Below This Function For Get All Revisions in Author Details With checked Duplicate .

According to your need.

function  get_all_revisions($post_id){


//get all revisions of particular Page Id & Post Id

$revision = wp_get_post_revisions($post_id);

$post_author_id = array();

foreach ($revision as $key => $value) {
    

    // Check Id Already Exists in Array 
     
    if ( ! in_array($value->post_author, $post_author_id)) {

        // Store Author Id 
        $post_author_id[] = $value->post_author;

        $get_author['author_link'] = get_author_posts_url($value->post_author); // Author Link
        $get_author['author_name'] = get_the_author_meta( 'display_name', $value->post_author ); // Author Display Name

        //Store All Author Details in Array
        $get_author_group[] =  $get_author;

     } 
        
     
    }
    
    return $get_author_group;

}

Usage :

// 2 is page or post id
$all_revisions = get_all_revisions(2); 

//print_r($all_revisions);

foreach ($all_revisions as $key => $value) {
    
    echo $value['author_link'].'<br>';
    echo $value['author_name'].'<br>';

}
2
  • You are so awesome.!!!Thank u very much! I will try it out and give you feedback later Dec 30, 2020 at 15:00
  • It's solved perfectly, u are so cool!!! Dec 31, 2020 at 3:26
0

I don't think you can get it by using any default function but sure you can use custom SQL for that.

global $wpdb;
$post_id = get_the_ID();
$revisions = $wpdb->get_results( "SELECT pt.post_author FROM $wpdb->posts pt WHERE 1=1 AND pt.post_parent = '$post_id' AND pt.post_type = 'revision' AND pt.post_status = 'inherit' GROUP BY post_author ORDER BY pt.post_author ASC" );
2
  • thank u! But, I am a novice, how to apply code ? Thanks for your advice Dec 30, 2020 at 8:26
  • How to use already exists in answer @Usage :
    – HK89
    Dec 30, 2020 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.