Home › Forums › Front-end Issues › Sub dividing posts in archive based on true/false › Reply To: Sub dividing posts in archive based on true/false
Instead of doing two new queries I would us a pre_get_posts filter
add_action('pre_get_posts', 'my_pre_get_posts');
function my_pre_get_posts($query) {
if (!$query->is_main_query() || is_admin()) {
// return
}
// other checks to make sure your altering the correct query
$query->set('posts_per_page', -1);
$query->set('meta_key', 'featured');
$query->set('orderby', array('meta_value_num' => 'DESC', 'date' => 'DESC');
}
The above alterations to the query will sort them with featured post 1st. Then in your loop you need to look at what the field value of the post is and do your separation when it changes from 1 to 0.
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.