Get Parent Custom Taxonomy Term and Color Div background

You’ll have to adjust the markup to suit your specific needs, but the easiest solution would use a post_class filter on the post_class() template tag, to output appropriate classes. For example, in your template, you need to call post_class(), such as: <div <?php post_class(); ?>> <div class=”car_type”>Ford</div> (background green) Post Title<br> Post Content<br> </div> Then, … Read more

Can’t pull metadata for a term in my theme’s function.php

woocommerce_add_to_cart_validation is a filter that is run in the add_to_cart_action method of the WC_Form_Handler class. This method is attached to the init hook. add_action( ‘init’, array( $this, ‘add_to_cart_action’ ) ); Your taxonomy is quite probably also registered at the init hook. The WooCommerce action has no priority set, so the default would be 10. I … Read more

Non-Recursive get_term_children()

Presumably you want to output term data, so you can use get_terms with the child_of argument, then iterate over returned terms and check that the parent of each term is your main term id: $parent_id = 42; $children = get_terms( ‘product_category’, array( ‘child_of’ => $parent_id ) ); foreach( $children as $child ) { if( $parent_id … Read more

Displaying Results From Custom Taxonomy Query

$regions = get_terms(‘region’, array(‘hide_empty’ => false) ); foreach( $regions as $region ){ ?> <li class=”location large-3 columns”> <img src=”https://wordpress.stackexchange.com/questions/126131/<?php echo get_template_directory_uri(); ?>/images/<?php echo $region->slug; ?>.jpg” alt=”” /> <span class=”location-title”><?php echo $region->name; ?></span> </li><?php }

get_terms returns array starting at 4

Run get_terms like this: var_dump(get_terms(‘category’,array(‘hide_empty’=>false))); And then like this: var_dump(get_terms(‘category’)); You should be able to infer what is happening. The first should return the zero based array you expect, with neatly numbered keys. The second does not. The only difference being the hide_empty argument. If you really must have a zero based array just pass … Read more