How to show parent taxonomy in wordpress

Topics focus on Web Developments, Programming, Database, Digital Marketing Tutorials, Code Snippets, SEO, Social Media Marketing and Inspirational articles.

How to show parent taxonomy in wordpress

How to show parent taxonomy in wordpress

Here I wrote the article about to show parent taxonomy in wordpress.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
	$taxonomyname='fruit';
	$toplevelterms = get_terms($taxonomyname, 'hide_empty=0&hierarchical=0&parent=0');
	$termchildren = array();
 
	foreach ($toplevelterms as $toplevelterm) {
		$termchildren[] = $toplevelterm->term_id;
	}
 
	foreach ($termchildren as $child) {
		$term = get_term_by('id', $child, $taxonomyname);
		$write .= '<li>';
		$write .= '<a href="' . get_term_link($term->name, $taxonomyname) . '">' . $term->name . '</a>';
		if ($term->description) $write .= apply_filters('the_content', $term->description);
		$write .= '</li>';
	}
	if ($write) echo '<ul class="clearfix">' . $write . '</ul>'; ?>

Pin It on Pinterest

Share This