Skip to content

Instantly share code, notes, and snippets.

@sectsect
Last active December 9, 2016 17:34
Show Gist options
  • Save sectsect/18efe28f210c2ece634e to your computer and use it in GitHub Desktop.
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.)
<?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