Support

Account

Home Forums General Issues orderby date picker field in get_terms Reply To: orderby date picker field in get_terms

  • Ordering terms in WP is tough. For the moment I’ve gone with the solid plugin,
    Custom Taxonomy Order NE. If I have time, I’ll likely pursue something along the lines of what you’ve laid out and update this post with progress and potential workaround for others.

    But if you can order your taxonomy with the above plugin it allows you inefficiently get an archive of posts by tax term. You can create a series of WP_Query calls that run through each term. Use get_terms() to create an array of all tax terms, then run a foreach over each term. This creates a WP_Query for each term item that will return all posts for a given term. Code to make this happen:

      // Get your terms and put them into an array
      $issue_terms = get_terms([
        'taxonomy' => 'issues',
        'hide_empty' => false,
      ]);
    
      // Run foreach over each term to setup query and display for posts
      foreach ($issue_terms as $issue_term) {
        $the_query = new WP_Query( array(
          'post_type' => 'post',
          'tax_query' => array(
            array(
              'taxonomy' => 'issues',
              'field' => 'slug',
              'terms' => array( $issue_term->slug ),
              'operator' => 'IN'
            )
          )
        ) );
    
        // Run loop over each query
        while($the_query->have_posts()) :
          $the_query->the_post();
    
          // YOUR TEMPLATE OUTPUT FOR EACH POST
    
        endwhile;
      }