Configure query with multiple categories in a custom order?

I am hoping that I understood your question, because recently I found myself needed to dynamically include a list of child categories and their count in a hierarchy menu in a post and so I came up with this:

I put this in file called listcat.php

<?php
/*
  Plugin Name: List Categories
  Reference: http://codex.wordpress.org/Template_Tags/wp_list_categories
  Description: Simple plugin to display categories in any post or page
  with a shortcode. It's basically a shortcode API interface to the
  wp_list_categories WordPress function.
*/
class ListCategories{
  static function list_categories($atts, $content = null) {
    $atts = shortcode_atts(
      array(
        'show_option_all'    => '',
        'orderby'            => 'name',
        'order'              => 'ASC',
        'style'              => 'list',
        'show_count'         => 0,
        'hide_empty'         => 1,
        'use_desc_for_title' => 1,
        'child_of'           => 0,
        'feed'               => '',
        'feed_type'          => '',
        'feed_image'         => '',
        'exclude'            => '',
        'exclude_tree'       => '',
        'include'            => '',
        'hierarchical'       => 1,
        'title_li'           => __( 'Categories' ),
        'show_option_none'   => __( 'No categories' ),
        'number'             => null,
        'echo'               => 1,
        'depth'              => 0,
        'current_category'   => 0,
        'pad_counts'         => 0,
        'taxonomy'           => 'category',
        'walker'             => null
      ), $atts
    );

    ob_start();
    wp_list_categories($atts);
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
  }
}

add_shortcode( 'categories', array('ListCategories', 'list_categories') );

once that is done, I include it in my header file (technically you
could put this anywhere but if you want it to be available to you
anywhere, then make sure its a part that loads everywhere, like a
header, footer, hooks or whatnot:

include '/server/path/to/the/file/listcat.php';

And then from any post, or page in the site you can use the shortcode
to generate the list and hierarchy (if you want) of the categories/or
child categories that you want dynamically and as they update, where
its included will automatically update too, no need to do it again or
manually update anything. Here is an example of what I did for myself:

[categories child_of=36 hide_empty=0 title_li='Explore Samples' orderby=id show_count=1]

and it produces this for me:

enter image description here


You can tweak this and style it to whatever you need, hope it helps you. I have also included the link to the Codex documentation so you can see what each option does and how it displays to help you decide what to use. Good luck.