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

Rewrite WordPress URL to show CPT meta field data

The post type query var is the same as the post type slug by default. Untested, but this should work- function custom_rewrite_basic() { add_rewrite_rule( ‘^books/([^/]+)/([0-9]+)/([^/]+)/?’, ‘index.php?books=$matches[1]&chapter=$matches[2]’, ‘top’ ); } add_action(‘init’, ‘custom_rewrite_basic’); $matches[3] will contain the chapter slug, but if you don’t need that to retrieve the chapter, then you don’t have to set it. Rewrite … Read more

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