Last active
December 9, 2016 17:34
-
-
Save sectsect/18efe28f210c2ece634e to your computer and use it in GitHub Desktop.
"get_the_terms" to the order of the "term_order". (order by ASC.)
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
<?php | |
/*================================================== | |
"get_the_terms" to the order of the "term_order". (order by ASC.) | |
================================================== */ | |
function get_the_terms_orderby_termorder($taxonomy){ | |
global $post; | |
$terms = get_the_terms($post->ID, $taxonomy); | |
$array = array(); | |
foreach($terms as $term){ | |
$array[$term->term_order] = (object)array( | |
"term_id" => $term->term_id, | |
"name" => $term->name, | |
"slug" => $term->slug, | |
"term_group" => $term->term_group, | |
"term_order" => $term->term_order, | |
"term_taxonomy_id" => $term->term_taxonomy_id, | |
"taxonomy" => $term->taxonomy, | |
"description" => $term->description, | |
"parent" => $term->parent, | |
"count" => $term->count, | |
"object_id" => $term->object_id | |
); | |
} | |
ksort($array); | |
$array = (object)$array; | |
return $array; | |
} | |
?> | |
<?php | |
/*================================================== | |
▼Usage Example (Get the slug) | |
================================================== */ | |
$orderterms = get_the_terms_orderby_termorder("mytaxonomy"); | |
if($orderterms){ | |
foreach($orderterms as $term){ | |
echo $term->slug; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment