Make WordPress Core

Opened 2 years ago

Last modified 11 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 12 months ago.
propose update_post_modified_date
24266.2.diff (2.7 KB) - added by nofearinc 12 months ago.
updated logic
24266.3.diff (2.8 KB) - added by nofearinc 12 months ago.

Download all attachments as: .zip

Change History (11)

comment:1 @nacin2 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.

comment:2 @nacin21 months ago

  • Component changed from General to Options and Meta

comment:3 @wonderboymusic16 months ago

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

@nofearinc12 months ago

propose update_post_modified_date

comment:4 @nofearinc12 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.

@nofearinc12 months ago

updated logic

comment:5 @nofearinc12 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.

@nofearinc12 months ago

comment:6 @nofearinc12 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.

comment:7 @johnbillion11 months ago

#30085 was marked as a duplicate.

comment:8 @jeremyfelt11 months ago

#30492 was marked as a duplicate.

Note: See TracTickets for help on using tickets.