Make WordPress Core

Opened 3 years ago

Last modified 12 months ago

#24266 new defect (bug)

update_post_meta doesn't change post modified date

Reported by: DennisSmolek Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.5.1
Component: Options, Meta APIs Keywords: has-patch
Focuses: Cc:


In building an application I wanted to query for posts that were modified since a specific date/time.

The only issue is the majority of our changes are to post meta and not to post content, this means these changes don't show up in the query.

To solve this I'm tying into the action, but I feel like this is something that should be done by default.

Attachments (3)

24266.diff (865 bytes) - added by nofearinc 13 months ago.
propose update_post_modified_date
24266.2.diff (2.7 KB) - added by nofearinc 13 months ago.
updated logic
24266.3.diff (2.8 KB) - added by nofearinc 13 months ago.

Download all attachments as: .zip

Change History (11)

#1 @nacin
3 years ago

Changing this would change behavior in a potentially un-expected way.

If wp_insert_post() added the ability to change metadata (something we've talked about), this could be solved. Interesting. I'm not even sure the easiest way to "bump" a post's modified date.

#2 @nacin
23 months ago

  • Component changed from General to Options and Meta

#3 @wonderboymusic
17 months ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

13 months ago

propose update_post_modified_date

#4 @nofearinc
13 months ago

  • Keywords has-patch added; needs-patch removed

A possible solution is a helper function update_post_modified_date that would update the modified date on add, update and delete. Sample use:

add_action( 'updated_postmeta', 'test_update_post_date', 10, 4 );
add_action( 'deleted_post_meta', 'test_update_post_date', 10, 4 );
add_action( 'added_post_meta', 'test_update_post_date', 10, 4 );

function test_update_post_date( $meta_id, $post_id, $meta_key, $meta_value ) {
	update_post_modified_date( $post_id );

I'm not a great fan of the the lack of a common action for updating (also, deleted_post_meta includes $meta_ids instead of $meta_id), but it could work.

13 months ago

updated logic

#5 @nofearinc
13 months ago

Moved to a core function that uses a global collection picking all changed post IDs where postmeta was changed, and updating the DB with cache clearing during the shutdown hook.

13 months ago

#6 @nofearinc
13 months ago

So, the first patch implements the idea of a helper function that could be applied by a plugin as discussed with nacin. The second one uses the global array for performance reasons but runs in core and collects all post IDs with updated metadata which is what we discussed with wonderboymusic. The third update updates only post metadata which was found thanks to an issue with Query Monitor by johnbillion that we debugged here.

#7 @johnbillion
13 months ago

#30085 was marked as a duplicate.

#8 @jeremyfelt
12 months ago

#30492 was marked as a duplicate.

Note: See TracTickets for help on using tickets.