Home Forums General Issues Order posts by date AND custom date


Order posts by date AND custom date

  • I have been able to find docs on how to order by a custom date field, but I have a specific use case requested by a client: they have 100s of blog posts from 10 years of posting. They update their posts with new information constantly but their permalinks have a date structure so updating the post date isn’t an option without breaking external links and references to each post, and htaccess redirection is also not an option since it would require a lot of time to do and keep track of everytime they update content.

    The solution I have come up with is to use ACF and create an “update_date” field that they can use to have the latest update date without messing with the post’s publish date. I know how to include posts in WP_Query by their post date OR custom field, which is great. The final piece of the puzzle is how to be able to query and order the posts by both fields as if they were the same parameter instead of 2 separate order parameters?

    Does anyone have any idea if this is possible and how it can be accomplished without using javascript (server side)? I know how to do it using jQuery, but I would rather build the query as needed instead of patching things up later.


  • There isn’t a way to order by two different fields at the same time using WP_Query(). I’m not even sure that this could be done with a direct DB query. These are two different columns in two different tables. The only way I can think of to accomplish what you want would be to copy the original post date to the new update field for every post and then sort them only on the new field.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Order posts by date AND custom date’ is closed to new replies.