0

I'm attempting to display custom columns that return the last modified date and the author that updated it.

function rh_custom_page_columns( $columns ) { $columns['last_modified'] = 'Last modified'; $columns['modified_author'] = 'Modified by'; return $columns; } add_filter('manage_pages_columns','rh_custom_page_columns'); function rh_custom_columns_date_author ( $column_id, $post_id ) { switch( $column_id ) { case 'last_modified': echo get_post_field('post_modified', $post_id); break; case 'modified_author': echo the_modified_author(); break; } } add_action( 'manage_pages_custom_column','rh_custom_columns_date_author', 10, 2 ); 

the_modified_author() doesn't return any value even though the author exists as a user. I've also tried get_the_modified_author() that outputs and empty value too.

How else can I display the author that modified the page (and not the author had originally published it)?

Researching it further, there seems to be a bug? with the function - https://wordpress.org/support/topic/get_the_modified_author-not-working/

1 Answer 1

2

get_the_modified_author does indeed return an empty value since WordPress does not provide a specific function to retrieve the author of the last modification by default.

An alternative is to use the wp_get_post_revisions function to retrieve the revisions of a post and then extract the author of the last revision. Here is the updated code that uses this method:

function rh_custom_page_columns( $columns ) { $columns['last_modified'] = 'Last modified'; $columns['modified_author'] = 'Modified by'; return $columns; } add_filter('manage_pages_columns','rh_custom_page_columns'); function rh_custom_columns_date_author ( $column_id, $post_id ) { switch( $column_id ) { case 'last_modified': $revisions = wp_get_post_revisions($post_id); if (!empty($revisions)) { $latest_revision = reset($revisions); echo get_post_field('post_modified', $latest_revision->ID); } break; case 'modified_author': $revisions = wp_get_post_revisions($post_id); if (!empty($revisions)) { $latest_revision = reset($revisions); $modified_by = get_userdata($latest_revision->post_author)->display_name; echo $modified_by; } break; } } add_action( 'manage_pages_custom_column','rh_custom_columns_date_author', 10, 2 ); 
1
  • Note: I’ve tried and tested a the wp_get_post_revisions function on my own since I had the same issue with blank values for get_the_modified_author Commented Jul 20, 2023 at 15:56

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.