0

My question is not a duplicate, because in my case posts have already been sorted by custom taxonomy term. The question is how to order posts by their category name AFTER they have been sorted by custom taxonomy.

This is for online scientific journal. I have posts attached to categories. Those posts are also attached to custom taxonomy called journals.

First I need to retrieve all the posts that are attached to specific custom taxonomy term. Then I need to list the posts ordering them by their category names.

This is the actual page I'm working on. Please, visit to get a better idea: http://journal.fledu.uz/en/journal/1-15-2017/

I'm thinking of prefixing all the category names so that I can order them by their names like this:

01 Some category name

02 Another category name

03 Category name

04 And so on

Here's my query:

$term = get_term_by( 'slug', get_query_var('term'), 

get_query_var('taxonomy') );
$term_date = get_term_meta($term->term_id, 'journal_date', true);

$journals = get_terms('journals');


$jurloop = new WP_Query(
    array( 
        'post_type' => 'post',
        'posts_per_page' => -1,
        'order'   => 'ASC',
        'tax_query' => array(
            array(
              'taxonomy' => 'journals',
              'field' => 'id',
              'terms' => $term, // Where term_id of Term 1 is "1".
              'include_children' => true
            )
          )
        )
    );

The the loop:

<?php if ($jurloop->have_posts()) :  ?>
   <?php while ( $jurloop->have_posts() ) : $jurloop->the_post(); ?>
            my stuff
   <?php endwhile; ?>
<?php endif; ?>

How can I order the posts by the names of the categories that they are attached to?

  • 1
    Possible duplicate of Ordering Posts List By Taxonomy Terms? – CodeMascot May 19 '17 at 18:37
  • My question is not a duplicate, because in my case posts have already been sorted by custom taxonomy term. The question is how to order posts by their category name AFTER they have been sorted by custom taxonomy. – Azamat May 20 '17 at 10:51
  • 1
    Ideally there is no after, you must do it all in the same query, the linked question is applicable in this case for understanding how to accomplish that. – Milo May 20 '17 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.