Set post terms on post publish

The argument from pending_to_publish action, $post_id in your case, is not ID but array (callback to publish). I think it would be better to use the publish_post action, that way $post_id will actualy be the post id. Also this is a very general action so if you have multiple post types it would be wise … Read more

get_terms problem : related articles

get_the_term_list() is retrieving the terms attached to the post that are in the taxonomy “types”. get_terms() is designed to retrieve all the terms within a taxonomy. What you are trying to do is use get_terms() for a specific term in a taxonomy, not a taxonomy itself. You need to do: $terms = get_terms(‘type’);

tax_query operator woes

I’m not sure that there is a way to get it to use ‘OR’ instead of ‘AND’. Alternatively, you can do: $myquery[‘tax_query’] = array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘regions’, ‘terms’ => array(‘region1’), ‘field’ => ‘slug’, ‘operator’ => ‘IN’ ), array( ‘taxonomy’ => ‘population’, ‘terms’ => array(‘pop1’), ‘field’ => ‘slug’, ‘operator’ => ‘IN’ ), … Read more

Changing stylesheet depending on custom taxonomy terms

Like Justin Tadlock says in your referenced article, the body_class() provides the ability to add classes dependant on the type of term. Given that you indicate your php knowledge is still growing; this maybe the best solution. The codex provides a list of classes on a body_class enabled: http://codex.wordpress.org/Function_Reference/body_class If that isn’t sufficient; wordpress has … Read more

Displaying terms by first letter

Try this code. <?php $taxonomy = ‘authors’;// e.g. post_tag, category $param_type=”authors”; // e.g. tag__in, category__in $term_args=array( ‘orderby’ => ‘name’, ‘order’ => ‘ASC’ ); $terms = get_terms($taxonomy,$term_args); if ($terms) { $first_letter = null; foreach( $terms as $term ) { $flag = 0; if( $first_letter != substr( $term->name, 0, 1 ) ) { $first_letter = substr( $term->name, … Read more

How do I determine if a certain term is in an array?

It depends on what kind of type are the values from your $product_terms array. If you have strings there, like term slugs, then you probably want to check if $term->slug exists. If you have objects, then make sure the array is indexed, and not associative. For associative arrays use array_key_exists() instead.