Support

Account

Home Forums ACF PRO Sort post by acf date first and after by title Reply To: Sort post by acf date first and after by title

  • There is a 3rd choice I just thought of.

    You could do one query, loop over the posts once to show the ones that have a date and then loop over them a second time to show posts without a date. Given that you are showing all posts this might be the way I would go.

    
    // posts with date value
    While (have_posts()) {
      the_post();
      if (get_field('date_field') == '') {
        // skip it
        continue;
      }
      // show this post
    }
    rewind_posts();
    // posts without date value
    while (have_posts()) {
      the_post();
      if (get_field('date_field') != '') {
        // end of posts without date, exit loop
        break;
      }
      // show this post
    }