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

Set terms in a custom post

I know this is an old question, but the tax_input array should probably look like this since it appears to be hierarchical like a category: ‘tax_input’ => array(‘artist-category’ => array( 3 ) //use the ID of the category, not the name of the category From WordPress Codex on wp_set_post_terms If you want to enter terms … Read more

Can I prevent the user from adding more than two levels deep of terms inside of a taxonomy metabox?

Unfortunately, this is not possible, at least not safe. The function wp_insert_term( $term, $taxonomy, $args = array() ) that handles the creation of taxonomies provides a few filters and hooks, but the only one before the creation of the term in the database is $term = apply_filters( ‘pre_insert_term’, $term, $taxonomy ); As you can see, … Read more

get_term and get_term_by return null or false, even though term exists

To use get_term_by we need the term object before it gets deleted. Therefore, we should use the action hook delete_term_taxonomy that runs before the term is deleted. Now, we can go ahead and perform some tasks such as deleting all the postmeta related to the term being deleted. The code is: add_action( ‘delete_term_taxonomy’, function($tt_id) { … Read more