Support

Account

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);