Adding directory to permalink for custom taxonomy posts
-
I have a menu that uses parent categories of a custom taxonomy as buttons. When activated, the menus that appear feature its child categories. When I click through to the page, the URL is something like this:
https://domain.com/taxonomy/child
How do I insert the parent as a directory before the child to read like this:
https://domain.com/taxonomy/parent/child
I’m currently using a custom structure for my permalink, with
/%category%/%postname%/
in that field. The function I’ve added looks like this:function myFunction() { $customTaxName = 'myTaxonomyOption'; $categories = get_terms( array( 'taxonomy' => $customTaxName, 'hide_empty' => false ) ); if ( !empty($categories) ) : foreach( $categories as $category ) : if( $category->parent == 0 ) : $output.='<div class="dropMenu">'; $output.= '<button class="btn">'. $category->name .'</button>'; $term_id = $category->term_id; $taxonomy_name = $customTaxName; $termchildren = get_term_children( $term_id, $taxonomy_name ); $output.= '<ul class="options-list">'; foreach ( $termchildren as $child ) : $term = get_term_by( 'id', $child, $taxonomy_name ); $output.= '<li><a href="'. get_term_link( $child ) .'">'. $term->name .'</a></li>'; endforeach; $output.= '</ul>'; $output.= '</div>'; endif; endforeach; echo $output; endif; }
I thought that if I added something before the
get_term_link( $child )
part it would work, but that just breaks my page. Is this a custom filter problem or maybe something in my permalink settings? This is currently running locally btw.Thanks in advance
- The topic ‘Adding directory to permalink for custom taxonomy posts’ is closed to new replies.