How to limit the number of terms (terms acts like categories)

number (integer) The maximum number of terms to return. Default is to return them all. http://codex.wordpress.org/Function_Reference/get_terms So… $terms = get_terms(‘new_category’,array(‘number’ => 5)); But there is a good chance that some of your terms will never show up. You will get the first five or the last five (in the example) depending on the sort order. … Read more

get_term_by not working when in functions.php

This is probably happening because the taxonomy you’re trying to query is registered yet. Eg. The WordPress environment is loaded when a theme’s functions.php file loads, but many plugins/themes/core functions don’t register taxonomies until later. Try hooking into init with a really high priority number and running the get_term_by function. Like so: <?php add_action( ‘init’, … Read more

Order terms by term_order

As this is one of the top results on Google and none of the above quite worked for me, this did seem to return terms in an order matching their display in the admin… get_terms([ ‘taxonomy’ => ‘whatever_you_want’, ‘meta_key’ => ‘order’, ‘orderby’ => ‘meta_value_num’ ]); In case it helps anyone, WP stores a value in … Read more

Add post classes for custom taxonomies to custom post type?

I found a snippet of code courtesy of mfields that solved this problem for me, here’s what I ended up using: <?php // Add custom taxonomies to the post class add_filter( ‘post_class’, ‘custom_taxonomy_post_class’, 10, 3 ); if( !function_exists( ‘custom_taxonomy_post_class’ ) ) { function custom_taxonomy_post_class( $classes, $class, $ID ) { $taxonomy = ‘listing-category’; $terms = get_the_terms( … Read more