Changing taxonomy term by slug (wp_update_term)

As you hinted in your question, you could use get_term_by() to return an object or array containing the term’s id, then use it to update that term. Something like this should work: $your_term = get_term_by( ‘slug’, ‘your_slug’, ‘your_taxonomy’ ); if ( false !== $your_term ) { wp_update_term( $your_term->term_id, ‘your_taxonomy’, $args ); } References: http://codex.wordpress.org/Function_Reference/get_term_by http://codex.wordpress.org/Function_Reference/wp_update_term

Use get_terms to get post_tags but limit to a taxonomy

I’m fairly certain that the taxonomies have nothing truly in common except posts that they share, so I think you can’t avoid running an actual query of posts, in order to learn which categories are candidates for your criteria. While, it may not be computationally the best method, you could do something like this… $args … Read more

Output terms to post_class()

The easiest and most straight-forward way to do this would be: $tax_terms = get_the_terms( $post->ID, array(‘genre’) ); $tax_terms = wp_list_pluck($tax_terms,’slug’); post_class(implode(‘ ‘,$tax_terms)); You could also apply a filter to post_class that does essentially the same. function tax_classes_wpse_105386($classes) { global $post; $tax_terms = get_the_terms( $post->ID, array(‘genre’) ); $tax_terms = wp_list_pluck($tax_terms,’slug’); $classes = array_merge($classes,$tax_terms); return $classes; } … Read more

using $wpdb to get custom post type with term

Any suggestions on how to get the title of the first custom post type of ‘property’ with the term ‘Locked’ in the taxonomy ‘status’? $args = array( ‘post_type’ => ‘property’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘status’, ‘field’ => ‘slug’, ‘terms’ => ‘locked’ ) ) ); $your_query = new WP_Query( $args ); while ( $your_query->have_posts() … Read more

Get posts of ONE taxonomy term of custom post type

You can try making the $args array more specific with: $args = array( ‘post_type’ => ‘portfolio’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘locations’, ‘field’ => ‘slug’, ‘terms’ => ‘paris’ ) ) ); Grabbed this snippet similar to one on the WP Query page in the codex. Also, this is assuming that your custom post type … Read more

get_terms that have custom sticky field checked

OK, got it <?php $types = get_terms( ‘tvr_amenity’, array( ‘parent’ => ‘0’, ‘hide_empty’ => 1 ) ); foreach( $types as $type ) : $myname = trim($type->name); $meta = get_option(‘amenity_sticky’); if (empty($meta)) $meta = array(); if (!is_array($meta)) $meta = (array) $meta; $meta = isset($meta[$type->term_id]) ? $meta[$type->term_id] : array(); $value = $meta[‘is_sticky’]; if(!$value) continue; /* skip term … Read more

Want wp_get_post_terms return in arbitrarily order, how to do?

add_filter(‘the_content’,’my_function’); function my_function($content){ the_post_thumbnail(‘thumbnail’, array(‘class’ => ‘top-post-img’ )); if (is_single() && in_category(‘5′)){ global $post; $term_list = wp_get_post_terms ($post->ID,’school’,array(‘fields’=>’names’)); ?> <div id=”some_class”> <span>School:<strong><?php print_r($term_list[0]); ?></strong></span> <?php if (is_single() && in_category(‘5′)){ $term_list = wp_get_post_terms ($post->ID,’article’,array(‘fields’ =>’names’)); ?> <span>Article:<strong><?php print_r($term_list[0]); ?></strong></span> <?php if (is_single() && in_category(‘5′)){ $term_list = wp_get_post_terms ($post->ID,’teacher’,array(‘fields’=>’names’)); ?> <span>Teacher:<strong><?php print_r($term_list[0]); ?></strong></span> </div> <?php return $content; … Read more