I have a custom post type with a bunch of custom meta values. I want to display a list showing 10 posts ordered by most recently modified.

My query args looks like this

$args = array(
    'post_type'              => array( 'post_type_harmonic' ),
    'posts_per_page'         => '10',
    'orderby'                => 'modified',
    'order'                  => 'DESC', 

The problem is that the order of the posts seems to be the publish date, not the modified date.

I need to either:

A) Modify the query so that 'modified' also includes updated/changes custom meta values, OR

B) perhaps the problem is that when I update a meta value

update_post_meta( $data, 'hd_meta_key', $today.' : The Post Was Accessed' );

Wordpress does not count this as a post 'modification'. Perhaps there is a way to update this as well? Maybe updating the_content is a way to trick WordPress into updating the modify date as well?

Thanks in advance!

  • You can create one more custom meta value to hold the modified date.
    – Patty
    Jun 7, 2022 at 22:09

1 Answer 1


Looks like I was on the right track.

using update_post_meta does not update the modified date of a post, so what you have to do is update the content of the post.

Luckily for me, I was not using the content, only custom meta. So updating the content with a random string whenever I updated post meta works. If you are using the content as well, then maybe updating the content with the same value will work as well (as in WordPress does not check to see if the content actually changed when marking as modified).

For those wondering, here is the code to update post content.

$my_post = array(
    'ID'           => $postID,
    'post_title'   => 'title of the post',
    'post_content' => 'content of the post',

// Update the post into the database
wp_update_post( $my_post ); 

I hope this helps someone else, as I think it's silly that updating meta values does not count towards post modify date :(

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.