how to show product custom taxonomies in woocommerce rest api

I eventually found a way using filters. I didn’t know there were filters for REST API responses… Here is my solution : add_filter( ‘woocommerce_rest_prepare_product’, ‘custom_products_api_data’, 90, 2 ); function custom_products_api_data( $response, $post ) { // retrieve a custom field and add it to API response $response->data[‘custom_taxonomy1’] = wp_get_post_terms( $post->ID, ‘custom_taxonomy1’, [] ); $response->data[‘custom_taxonomy2’] = wp_get_post_terms( … Read more

ACF Field, hide taxonomy title and image when no nothing selected in post

Seems the your post doesn’t attach any taxonomy. So just try to replace your code with this: <?php global $post; $tax = ‘directory_features’; $terms = get_the_terms($post,$tax); if ( $terms && ! is_wp_error( $terms ) ){ foreach( $terms as $term ) { $term_link = get_term_link( $term ); $image = get_field(‘svcta_favorites_image’,$term); if( $term->count > 0 ) { … Read more

List all taxonomies with their descriptions

This worked… function list_cats_with_desc() { $base = wp_list_categories(‘echo=0&hide_empty=0&title_li=0&orderby=ID&order=ASC&taxonomy=CUSTOM-TAXONOMY-SLUG’); // wp_list_categories adds a “cat-item-[category_id]” class to the <li> so let’s make use of that! // Shouldn’t really use regexp to parse HTML, but oh well. // (for the curious, here’s why: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 ) $get_cat_id = ‘/cat-item-[0-9]+/’; preg_match_all($get_cat_id, $base, $cat_id); // Let’s prepare our category descriptions to … Read more

Body class to each level of a hierarchical custom taxonomy

Use is_tax instead of is_category, and update get_ancestors to get taxonomy from the queried object: add_filter( ‘body_class’, ‘custom_cat_archiev_class’ ); function custom_cat_archiev_class( $classes ) { if ( is_tax( [‘custom_tax_1’, ‘custom_tax_2’] ) ) { $term = get_queried_object(); $ancestors = get_ancestors( $term->term_id, $term->taxonomy, ‘taxonomy’ ); $classes[] = ‘catlevel-‘ . ( count( $ancestors ) + 1 ); } return … Read more

Filter Tags for current users

This is a possible way of doing this. Whenever a new term is created, you execute the following code. This code saves the current user_id as the term author, which should allow you to filter by user_id when fetching terms. add_action( ‘created_term’, ‘filter_user_specific_term’, 10, 3 ); function filter_user($term_id, $tt_id, $taxonomy){ if( $taxonomy == “my_custom_taxonomy”){ if … Read more