get_terms_args ordering by meta key not working

After a lot of searching and tests… Finally I’ve found a solution. Instead using get_terms_args filter, I’ve changed to parse_term_query action. My resulting code looks this way now: add_action(“parse_term_query”, “MyTheme_ParseTermQuery”, PHP_INT_MAX, 1); function MyTheme_ParseTermQuery(&$query) { $taxonomy = $query->query_vars[‘taxonomy’][0]; if($taxonomy == “edition”){ $query->query_vars[‘order’] = “ASC”; $query->query_vars[‘orderby’] = “meta_value_num”; $query->query_vars[‘meta_query’] = [[ ‘key’ => “_edition”, ‘type’ => … Read more

What is the “meta” key in WP_Term Object?

Looking at the source, that meta property isn’t a standard property in the WP_Term object. However, a plugin/theme can add custom properties to the object using the get_term or get_{taxonomy} filter: add_filter( ‘get_term’, function( $term ){ $term->meta = get_term_meta( $term->term_id ); // all metadata return $term; } );

How to filter custom taxonomy term name, slug, and description?

The default fields name, slug and description are not term metadata, so you should instead use wp_update_term() to update those fields. So just replace those three add_term_meta() with: wp_update_term( $term_id, ‘codes’, [ ‘name’ => $name, ‘slug’ => $slug, ‘description’ => $desc, ] ); Additionally, instead of using $_POST, I would use get_term() to get the … Read more

How to get the $meta_type given the $object_id

Given the $object_id (and a WP_Term object), how does one go about determining the $meta_type to be passed to update_metadata()? Unfortunately, that is not possible because each object has its own table and therefore the same ID (1, 2, 3, etc.) could refer to a post, comment, term, etc. So that’s why we have different … Read more

Query Custom Post Type by Taxonomy Meta Value

This isn’t possible via WP_Query, but more importantly, this would be stupendously expensive. Taxonomy queries are expensive. Post meta queries are super super expensive. Like queries are also expensive. Finding all posts that have a term that has a meta that is like X, is an astoundingly expensive/slow query. Writing this out as a custom … Read more

Failure to add term meta

This turned out to be a database issue. Due to some security measures put in place by the infrastructure team, the network upgrade script was prevented from completing the upgrade on all sites. Thus, for the specific site within our WordPress Network on which this plugin was being tested, the wp_termmeta table had not been … Read more