Get_term_meta() always returns false
Get_term_meta() always returns false
Get_term_meta() always returns false
Is it possible to add Term Meta Fields to a WooCommerce Attribute?
I figured it out: update_term_meta( $term_id, ‘organization’, $_POST[‘organization’], true ); should have been update_term_meta( $term_id, ‘organization’, $_POST[‘organization’] ); Where the fourth parameter makes it unique.
How to exit out of delete_categories and stop action?
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
You can use get_terms(): <?php $args = array( ‘taxonomy’ => ‘name-of-the-category’, ‘meta_query’ => array( array( ‘key’ => ‘ref’, ‘value’ => ‘53113’, ), ), ); $terms = get_terms( $args ); You would get an array of terms, where the ref value would be 53113.
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; } );
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
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
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