Skip to content

Instantly share code, notes, and snippets.

@JiveDig
Created October 23, 2013 14:58
Show Gist options
  • Save JiveDig/7120383 to your computer and use it in GitHub Desktop.
Save JiveDig/7120383 to your computer and use it in GitHub Desktop.
Custom post type category sort using get_terms() (orderby doesn't work here!)
// Add product category sort
add_action( 'genesis_before_loop', 'orc_product_category_sort' );
function orc_product_category_sort() {
if ( is_post_type_archive( 'product' ) OR is_tax( 'product_cat' ) ) {
$portfolio = site_url('/shop/');
echo '<a name="sort"></a>';
echo '<div class="category-sort">';
echo '<div class="entry-categories">Sort by: <a href="' . $portfolio . '#sort" alt="Show all portfolio categories">Show All</a>';
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false
);
$terms = get_terms( 'product_cat', $args );
foreach ( $terms as $term ) {
echo '<a href="' . get_term_link( $term ) . '#sort">' . $term->name . '</a>';
}
echo '</div>';
echo '</div>';
$term_name = single_cat_title( $prefix = '', $display = false );
echo '<h1 class="entry-title" itemprop="headline">' . $term_name . '</h1>';
} // if
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment