Home › Forums › General Issues › WP_Query – sort by custom field and publish date › Reply To: WP_Query – sort by custom field and publish date
You can’t work out how to do this because there is no way to do what you are attempting to do.
WP does not have a way to sort by 2 different values depending on which one exists. You would need to make the display date required or you would need to dynamically populate that field with the post date if no value is entered. Use an acf/save_post filter get the post date and update the field
update_field('date_field', get_the_date('Ymd', $post_id), $post_id);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.