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
}
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.