get_the_modified_author() not working |



Are you looking directly at the database, and seeing no entries for _edit_last in the post_meta table?
The WP code definitely sets the value in several places.
Or are you saying it worked at one point and doesn’t now? Did you do any cleanup on the database?
The modified date is a column in the posts table, but the modified author is in post meta. The _edit_last is used to compare against the user when checking the post lock _edit_lock meta. One test you can try is to try to edit a post from two user accounts at the same time. The second one should get a message that the post is locked, and it will say by who, which is the _edit_last field.

Hi @joyously

Thanks for your reply and ideas. I checked the points you were making.

In the database I looked at the postmeta table and found some _edit_last entries, but none for the posts in my post list. The ones I found were 1 for a media file, 1 for the standard privacy page and the rest are for custom posts. So none for standard posts, and none for my own pages.

I don’t know if it ever worked. It is a prototype I am working on. It’s been up for a few weeks now.

The strange thing is that I did the test that you suggested and in the second browser I got a message that the post I was editing in the first browser was being edited and the name was given. This leads me to the idea that _edit_last is being set while editing, but does not get into the database (or is deleted) after the editing is done. This sounds rather strange to me, but I will look into this.

The only difference I see between the standard posts and pages is that my custom posts have 'show_in_rest' => false, as I don’t want them exposed to the outside world.

I’ll check some more and report here. Any ideas in the meantime are appreciated.

Just checked some more. While editing a (normal) post there is no meta data entry in the postmeta table for _edit_last.

I do see in another browser that the post is being edited and by who.

Further checking revealed that there is a function wp_check_post_lock() that is being used while populating the post list. And the source for this function tells me that if the second part of the _edit_lock meta data is set (which it is) it will take that as the user id. So the fact that I can see that a post is being edited in the post list depends upon the _edit_lock meta data entry, which is there. It seems to be there also for posts that have been edited, but are not currently being edited. Which suggests that _edit_last is not the correct meta data entry to be checked in the get_the_modified_author() function. This takes me back to the beginning, where I suspected that get_the_modified_author() might be buggy. I’ll do some more testing.

See here for the source codes:

@joyously or anyone else: any reactions?



By the way, what version of WP are you running, and which editor are you using?

To anyone that is still following:

Using the function get_the_modified_author() seems to be broke for regular posts and pages. It seems to work for custom posts.

Looking at the source of wp_check_post_lock() I made a function:

function abc_get_user_id( $post_id ) {
    $lock = get_post_meta( $post_id, '_edit_lock', true );
    if ( ! $lock ) {
        return 0;
    $lock = explode( ':', $lock );
    $time = $lock[0];
    $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true );
    return $user;

This function seems to return the user id of the last user that edited the post. It works for regular posts, pages and custom posts.

Any reactions appreciated.


Sorry, I missed your reaction.
It’s the latest version: WP 5.4.1. Using the block editor for post and pages. And the old editor for custom posts (had to set 'show_in_rest' => false, because i do not want the custom posts to be exposed to the outside world, and then you are stuck with the old editor, which is a different nuisance…)

Source link