0

I am having trouble retrieving an array item from WordPress revisions array. I have Googled and no answer I have come across has worked so far. What I am trying to do is create a list of all Authors who have done revisions of a post so I can display this in a dashboard. The rest I can complete just having issues getting the item from the array.

$arrayz =  '[0]=>
  object(WP_Post)#4970 (24) {
    ["ID"]=>
    int(224)
    ["post_author"]=>
    string(1) "1"
    ["post_date"]=>
    string(19) "2019-11-18 23:93:39"
    ["post_date_gmt"]=>
    string(19) "2019-11-18 23:13:39"
    ["post_content"]=>
    string(24) "New content added here"
        }';

echo '<pre>';
var_dump($arrayz);
echo '</pre>';
// Getting error here
echo $arrayz[0]["post_author"];
4
  • What is the error you are getting? Commented Nov 19, 2019 at 23:49
  • [Illegal string offset 'post_author' on line Commented Nov 20, 2019 at 0:00
  • Is this code exactly how you are running it? If so, then $arrayz is just a string. What is the output of var_dump? What if you var_dump($arrayz[0])? Commented Nov 20, 2019 at 0:21
  • I am running $revisions = wp_get_post_revisions($post->ID); and then using var_dump($revisions); but in my snippet I just created an array with only one return. Commented Nov 20, 2019 at 0:24

1 Answer 1

1

To get the post author ID you can try:

$revisions = wp_get_post_revisions($post->ID); 
//For first author
$first_author = $revisions[0]->post_author;
//to get all revision authors
foreach( $revisions as $revision ){
    echo $revision->post_author;
}
1
  • Thanks! this worked for me in the loop! Commented Nov 20, 2019 at 0:53

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.