I work with several front-end editors only. in these cases where the editors are very different and are not flexible! I use code snippets to display a piece of information I need in a consistent way everywhere.
it's so simple that I feel like no one understands what I'm doing or trying to do. please read carefully and look at the illustrations.
In my case today
I have a taxonomy called "property_city" attached to the CTP "property" (nothing extraordinary)
its interests me because I want to display its terms in this way [Parent] -> [Child of parent] -> [Child of parent] -> etc all in hierarchy way
let's try to post an ad ok?
my apartment is located in manhattan so I selectd manhattan. by default the parent New York are not displayed.
with this snippet code it's possible
(/!\ don't be confused, we only use snippet codes no php files or templates to modify. we just inject a snippet./!)
function taxonomy_hierarchy() {
global $post;
$post_id = $post->ID;
$return = '';
$terms = wp_get_post_terms( $post->ID, 'property_city' ); //Put your custom taxonomy term here
foreach ( $terms as $term ) {
// this gets the parent of the current post taxonomy
if ($term->parent != 0) {
$return .= $term->name. ', ' .get_term( $term->parent, 'property_city' )->name;
} else {
$return .= $term->name;
}
}
return $return;
}
add_shortcode( 'parent-child', 'taxonomy_hierarchy' );
Done! New York,Manhattan now displayed.
My question is how to make this shortcode [parent-child] MORE flexible? with just output a text (=nolink) parameter or output links (=link).
in our example it will look like that
[parent-child=nolink] for my loops for e.g.
[parent-child=link] for the posts.
thanks if you have any idea how to do it


