Does WordPress Offer a Way to Find All of the Categories that Don’t Have Children?

There is no way easy way to do that. You have to query directly to achieve that. I am assuming, you only want the parent categories which don’t have descendants or even if they have descendants, it’s not used in any post global $wpdb; $categories = $wpdb->query(“SELECT $wpdb->terms.* FROM $wpdb->terms INNER JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id … Read more

has_term() does not return when term is assigned post?

I suspect that the Codex information for has_term() is incorrect: <?php has_term( $term, $taxonomy, $post ) ?> And for the $taxonomy parameter: $taxonomy (string) (optional) Taxonomy name Default: ” But if you look at the source for has_term(): $r = is_object_in_term( $post->ID, $taxonomy, $term ); So, $taxonomy is passed to is_object_in_term(): <?php is_object_in_term( $object_id, $taxonomy, … Read more

Get random terms

Unlike a normal WP_Query(), get_terms() or WP_Term_Query() does not have random ordering. You would either need to do it in SQL yourself or grab all the terms and shuffle them, pulling out 6 to make your random term array: // Get all terms $terms = get_terms( array( ‘taxonomy’ => ‘webshops’, ‘hide_empty’ => false, ) ); … Read more

Custom taxonomy term as class?

You could do something like this <?php $terms = get_the_terms( $post->ID, ‘taxonomy_name’ ); ?> <div class=”myclass<?php foreach( $terms as $term ) echo ‘ ‘ . $term->slug; ?>”> <!– content –> </div> http://codex.wordpress.org/Function_Reference/get_the_terms

Programmatically add terms to custom post types

I find out the problem and the solution. I debugged the “wp_set_object_terms” by using “is_wp_error” and I got “Invalid Taxonomy” message, then I realized that when the posts was being created that term didn’t exists. So I change the hook to “init” in the programmatically_create_post() function, and voila! Below this line the code working: <?php … Read more