Articles of term meta

Get term by custom term meta and taxonomy

How to get term by custom term meta and taxonomy or how to filter tax_query by term meta instead slug/id? function custom_pre_get_posts($query) { global $wp_query; if ( !is_admin() && is_shop() && $query->is_main_query() && is_post_type_archive( “product” )) { $term = ???get_term_by_meta_and_taxonomy???(‘custom_meta_term’,’my_taxonomy’); $t_id = $term[‘term_id’]; $tax_query = array ( array ( ‘taxonomy’ => ‘my_taxoomy’, ‘field’ => ‘id’, […]

Adding custom ID field to the categories

I’m writing a plugin for importing products and categories from another CMS into WordPress (with Woocommerce). To keep the structure of categories and to put products into the right categories I would like to use custom IDs (not the ones generated by WordPress) of categories from the source CMS instead of category names as a […]

WP_Query, tax_query and term_meta: How to?

I have a custom post type product (wine). Each of the following is a custom taxonomy: Vintage (Year of harvesting) [only one per wine] Family (Grape variety) [may be more than one] Size (Bottle Size) [only one per product] In the single product view of a wine I want to do the following queries: 1) […]

Using get_terms() with meta_query parameters

Im trying to build a taxonomy query to only display the terms that have a certain custom field value assigned to it. The custom field holds a boolean value, so I tried: $args = array( ‘taxonomy’ => ‘product_cat’, ‘hide_empty’ => false, ‘meta_key’ => ‘featured’, ‘meta_value’ => true ); Also: $args = array( ‘taxonomy’ => ‘product_cat’, […]

Failure to add term meta

I’m working on a modification to a custom taxonomy that would allow content managers to specify a numeric order in which the terms shall appear in a widget. They can’t rely on the alphabetical order in this case. I’ve used this tutorial to add an input[type=number] to the entry and edit forms, and that’s working […]

How to include term custom meta into the custom taxonomy term permalink structure

I made a custom taxonomy and I’m trying to customise the permalink structure for each term by using term custom meta. At the moment I have a custom post type magazine_article and a custom taxonomy magazine. My aim is to get a structure as follows: /magazines/ archive for magazine_article post type served by archive-magazine_article.php /magazines/15/ […]

Get ID of current taxonomy in register_rest_field

I have a term field created with types plugin and attached to the “category” taxonomy. I need to get this field in the api rest. You cant get the termmeta in types plugin like this types_render_termmeta($slug_term, array(“term_id” => $term_id)); I don’t know how to get current category id in register_rest_field function. register_rest_field( ‘category’, ‘color’, array( […]

Add custom taxonomy fields when creating a new taxonomy

Edit: Important note for WordPress v4.4 onward This question used a great workaround for the lack of real term meta in older versions of WordPress, but since the release of WordPress v4.4, real term meta has been introduced, and that’s definitely the way to go now. Here’s a post that looks like a good starting […]