Support

Account

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.