New answers tagged

0

Sort terms by array value 'order' instead of array key. If you have 2 items with same key, last one will override first one. This will prevent that and make all of them visible: $sorted = array(); $args = array( 'hide_empty' => false ); $terms = get_terms( 'my-tax', $args ); if( $terms ) : foreach ( $terms as $term ) { $sorted[] = ...


0

This is the best i could do. It gives what's wanted, but as i said it displays category in url instead what should be "fixture". Still, works fine. term_id; // category $category_link = get_category_link( $catID ); ?> " title="Category Name">View More


0

Use get_terms and specify name and parent. $name = 'Flowers'; $parent_id = 42; $args = array( 'name' => $name, 'parent' => $parent_id ); $terms = get_terms( 'category', $args );


0

Easiest way: $rootId = end( get_ancestors( $term_id, 'my_taxonomy' ) ); $root = get_term( $rootId, 'my_taxonomy' ); echo $root->name;


3

FINAL EDIT From comments Unfortunately when I try method one, all links go back to the homepage As I stated, everything works on my test install. I actually forgot that your code works for you, because you have hardcoded the URL <a href='/?$tax=$slug' ><h5> $term->name </h5></a> What this tells me is that get_term_link() ...


3

This could be done in the template that displays your archive page when only one post is returned by wp_query for a given category. Something like this: if ( $wp_query->post_count == 1 && $wp_query->max_num_pages == 1 ) { wp_redirect( get_permalink( $wp_query->posts['0']->ID ) ); exit; }


0

https://pl.wordpress.org/plugins/taxonomy-terms-order/ This plugin does what you want, you can easily manage order.


0

How about ordering by count? $categories = get_terms( 'category', array( 'orderby' => 'count', ) ); Reference: get_terms



Top 50 recent answers are included