Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Created May 20, 2015 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save remcotolsma/5263263b6fbb6b9018ee to your computer and use it in GitHub Desktop.
Save remcotolsma/5263263b6fbb6b9018ee to your computer and use it in GitHub Desktop.
Custom WordPress the_terms() function to sort the post terms by "Category Order and Taxonomy Terms Order".
<?php
/**
* The terms
*/
function prefix_the_terms( $post_id, $taxonomy ) {
$term_ids = wp_get_post_terms( $post_id, $taxonomy, array(
'fields' => 'ids',
) );
$terms = get_terms( $taxonomy, array(
'include' => $term_ids,
'orderby' => 'term_order',
'order' => 'ASC',
'hide_empty' => false
) );
$links = array();
foreach ( $terms as $term ) {
$link = $link = get_term_link( $term, $taxonomy );
$links[] = sprintf(
'<a href="%s" rel="tag">%s</a>',
esc_attr( $link ),
esc_html( $term->name )
);
}
echo implode( ', ', $links );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment