Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Created April 29, 2015 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredatch/7848bdbfd51b09976750 to your computer and use it in GitHub Desktop.
Save jaredatch/7848bdbfd51b09976750 to your computer and use it in GitHub Desktop.
Manually weighted taxonomy terms
<?php
// Use this plugin https://wordpress.org/plugins/i-order-terms/ which will let you drag/drop to re-order terms
// get_terms() will automatically order the terms
// get_the_terms() needs to be sorted afterwards. Example below.
function object_to_array( $object ) {
if ( is_array( $object ) OR is_object( $object ) ){
$result = array();
foreach( $object as $key => $value ){
$result[$key] = object_to_array( $value );
}
return $result;
}
return $object;
}
$terms = get_the_terms( get_the_ID(), 'some_taxonomy' );
if ( $terms && ! is_wp_error( $terms ) ) :
// Deep convert to array
$terms = object_to_array( $terms );
// Order by custom_order tag
usort( $terms, function($a, $b) {
return $a['custom_order'] - $b['custom_order'];
});
foreach( $terms as $term ) {
echo $option['name'];
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment