Created
November 29, 2023 01:29
-
-
Save dantetesta/b4c800eda11e31bc8203d1f70eaccf4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function show_taxonomy_lista() { | |
$nome_tax = 'estados'; | |
$CSS = ' | |
<style> | |
.tax-style { | |
font-size: 16px; | |
color: #333333; | |
} | |
.tax-parent { | |
font-weight: bold; | |
} | |
.tax-child { | |
margin-left: 10px; | |
} | |
</style> | |
'; | |
$rd_terms = wp_get_post_terms(get_the_ID(), $nome_tax, array("fields" => "ids")); | |
if ($rd_terms) { | |
$term_array = trim(implode(',', (array) $rd_terms), ' ,'); | |
$neworderterms = get_terms($nome_tax, 'orderby=none&include=' . $term_array); | |
$output = ''; | |
foreach ($neworderterms as $orderterm) { | |
if ($orderterm->parent == 0) { | |
$output .= '<div class="tax-style tax-parent">' . $orderterm->name . '</div>'; | |
$children = get_terms($nome_tax, array('parent' => $orderterm->term_id, 'orderby' => 'none')); | |
if (!empty($children)) { | |
foreach ($children as $child) { | |
if(in_array($child->term_id, $rd_terms)){ | |
$output .= '<div class="tax-style tax-child">' . $child->name . '</div>'; | |
} | |
} | |
} | |
$output .= '<br>'; | |
} | |
} | |
echo $CSS . '<div class="tax-style">' . $output . '</div>'; | |
} | |
} | |
add_shortcode('tax_list', 'show_taxonomy_lista'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment