Display custom post type in hierarchical order with get_terms

Try something like this: <?php $parent_terms = get_terms( ‘name_of_your_taxonomy’, array( ‘parent’ => 0, ) ); foreach ( $parent_terms as $parent_term ) { $child_terms = get_terms( ‘name_of_your_taxonomy’ array( ‘child_of’ => $parent_term->term_id, ) ); foreach ( $child_terms as $child_term ) { $args = array( ‘post_type’ => ‘product’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘name_of_your_taxonomy’, ‘field’ => ‘slug’, … Read more

get_terms orderby numeric

You can use usort to sort the object $children. The function to sort after you got the $children object can be like this: usort( $children, function($a, $b) { $ai = filter_var($a->name, FILTER_SANITIZE_NUMBER_INT); $bi = filter_var($b->name, FILTER_SANITIZE_NUMBER_INT); if ($ai == $bi) { return 0; } return ($ai < $bi) ? -1 : 1; });

get_template_part for each level of taxonomy term

Creating and including a template for your custom post type archive is easy, you just need to create a archive-{$post_type}.php template, WordPress will automatically use that template whenever you visit that particular post type’s archive page. Just remember to set the has_archive parameter when registering your post type. As for the taxonomy archive page, you … Read more

Parent & Child Taxonomy slugs in custom post permalink

To handle the extra URL segment you need to add another rewrite rule similar to the one generated by add_permastruct, but with an extra capture group and slash for the additional level of terms: add_rewrite_rule( ‘book/([^/]+)/([^/]+)/([^/]+)-blah-blah-blah?(:/([0-9]+))?/?$’, ‘index.php?post_type=book&name=$matches[3]’, ‘top’ ); Also, as I mentioned in my comment, the query var and slug author are already in … Read more

Permalink Structure CPT With Custom Taxonomy Fails

Setting has_archive to true causes WordPress to generate a rewrite rule for the archive using the rewrite slug, which is not what you want in your case. Instead, explicitly specify the archive slug as a string and the correct rules will be generated: $args = array( ‘has_archive’ => ‘courses’, ‘rewrite’ => array(‘slug’ => ‘courses/%course-type%’,’with_front’ => … Read more