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 use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.