I am currently trying to re-order the categories displayed in a posts metadata.

The general functionality is that the order of category display is alphabetical (eg: categories - Global, Your Voice).

Im trying to get the order of the categories on posts to instead be ordered by the post count (number of posts under each category).

I tried adding the general orderby query and set the value to count, but with no luck, any ideas?

This is the output code for the category metadata -

<?php lsx_post_meta_category(); ?>

Kind regards, Joseph Hart

  • lsx_post_meta_category() is not a standard WordPress function. Please share the whole content of that function with us, otherwise we can't help you debug it. – swissspidy Jan 17 '18 at 10:39
  • Hi thank you for the response. This is a custom theme function from the LSX theme - wordpress.org/themes/lsx It seems to be a custom function similar to <?php the_category(', ') ?> - codex.wordpress.org/Post_Meta_Data_Section My general understanding would be to include the function with the orderby parameter as so, but this has not worked: lsx_post_meta_category('orderby=count'); – Joseph Hart Jan 18 '18 at 14:52
  • Please view the whole function located within the post-content.php template: <?php } ?> <span><?php the_title(); ?></span> </h1> </header><!-- .entry-header --> <?php //} ?> <div class="entry-meta"> <?php lsx_post_meta_date(); ?> <?php lsx_post_meta_author(); ?> <?php lsx_post_meta_category(); ?> </div><!-- .footer-meta --> – Joseph Hart Jan 18 '18 at 15:00
  • Managed to configure a solution. The custom function <?php lsx_post_meta_category(); ?> was outputting the meta category data according to a specific layout function in the functions.php. The function starts as follows: function lsx_post_meta_category() { $post_categories = wp_get_post_categories(get_the_ID()); I updated: $post_categories = wp_get_post_categories( get_the_ID()); To: $post_categories = wp_get_post_categories( get_the_ID(), array('orderby' => 'count', 'order' => 'ASC') ); This array adds the required sorting to the category meta-data – Joseph Hart Jan 19 '18 at 11:02

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.