Get terms parent ID for conditional IF statement

While this is not specifically WordPress but some general PHP, here’s a solution which you could use: $terms = get_the_terms( $post->ID , ‘prodcats’ ); foreach( $terms as $term ) { $classes=”categoryblock”; switch( $term->parent ) { case 3: $classes .= ‘ blue’ // Notice the space between the opening string – important for CSS break; } … Read more

Wrap custom terms loop

Here is solution, split in arrays: <?php foreach (array_chunk(get_terms( ‘razotajs’, ‘orderby=count&order=DESC&hide_empty=0&parent=0’ ), 6, true) as $array) { echo ‘<div class=”logo_sets”>’; foreach($array as $cat) { ?> <a href=”https://wordpress.stackexchange.com/questions/224950/<?php echo get_term_link($cat->slug,”razotajs’); ?>” title=”<?php echo $cat->name; ?>”><img src=”<?php echo z_taxonomy_image_url($cat->term_id); ?>” alt=”<?php echo $cat->name; ?>” /></a> <?php } echo ‘</div>’; } ?>

Unable to retrieve any child terms using get_terms

Try relying on the new WP_Term_Query() class, here’s an example per your code: // WP_Term_Query arguments $args = array( ‘taxonomy’ => ‘carabana_Cat’, ‘hide_empty’ => false, ‘orderby’ => ‘description’, ‘child_of’ => 28) ); // The Term Query $term_query = new WP_Term_Query( $args );

Order terms by creation date

If you want to achieve that, then you need to add creation_date for each taxonomy, hooked with ‘create_category’ (or create_YOURTAXONOMYNAME) function. lets say,for example, you add a new category : add_action( “create_category”, ‘my_func123’, 10, 2 ); function my_func123( $term_id, $tt_id){ update_option(‘my_taxnm_date_’.$term_id, time()); } then later, anytime, you will be able to get the creation date … Read more

How to show only tagged CPT categories / taxonomies for a custom post type?

wp_get_object_terms! For example, if we want to grab all terms in a product taxonomy for a post we might do: $product_terms = wp_get_object_terms( $post->ID, ‘product’ ); if ( ! empty( $product_terms ) ) { if ( ! is_wp_error( $product_terms ) ) { echo ‘<ul>’; foreach( $product_terms as $term ) { echo ‘<li><a href=”‘ . get_term_link( … Read more

Change the last separator in the_terms

$terms = get_the_term_list( $post->ID, ‘post_tag’, ‘Tags: ‘, ‘, ‘, ”); echo preg_replace(‘/^(.+),([^,]+)$/’, ‘$1 &$2’, $terms); Explanation for /^(.+),([^,]+)$/: / – delimiter ^ – string beginning .+ – 1 or more characters [^,]+ – 1 or more characters that are not a comma $ – string end $n is the nth match i.e. nth pair of … Read more