What is the difference between terms and tags?

Simple yet tough question, taxonomies are just groups of categories, while terms are just single categories within these groups.* So, for example, if you create a new post and choose category for it – the category itself is a term, and opening YourWordpressURL/wp-admin/edit-tags.php?taxonomy=category you’re going to see all the categories (taxonomy). Terms and Tags are … Read more

WordPress 4.4+ breaks Walker Extension

Your original solution was a hack, and no surprise it failed. In general never add methods/attributes to objects that you do not control their class and future development. The right way is to create your own object to be passed to the walker. Pass to it the category object on construction and either populate fields … Read more

Get second level terms of custom taxonomy

You can use PHP’s array_filter to process the results of a taxonomy query function that returns its results, and then display them. Something like: # This returns the whole taxonomy… $whole_tax = get_terms(‘customtax’, array(‘hide_empty’ => 0)); $second_level = array_filter($whole_tax, function ($t) { # This term has a parent, but its parent does not. return $t->parent … Read more

Creating a non-removable taxonomy term

Update Indeed, there is a way to define one term per taxonomy as default term which makes it non-deletable from the admin GUI. WP_Terms_List_Table looks for an option get_option( ‘default_’ . $this->screen->taxonomy ). So if you have a custom Taxonomy called genre, you have to set an option default_genre with the term-id of the term … Read more

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

Fixing category count

If you just want to update the counts of posts in each term, wp_update_term_count_now( $terms, $taxonomy ) should do it… just pass the terms affected as an array and run it once for each taxonomy you have. You can also call wp_defer_term_counting( true ) before inserting new rows, and then after adding your posts, catch … 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