wp_insert_term is adding a term that has no name

As noted in the OP’s comments, some non-ASCII characters may not be supported in term names under certain conditions. To replace all suspect characters with an underscore, use the following code: $categoryname = preg_replace(‘/[^a-z0-9]/i’, ‘_’, strtolower($categoryname)); wp_insert_term($categoryname, “department”); To replace all suspect characters with a dash, use the following code: $categoryname = preg_replace(‘/[^a-z0-9]/i’, ‘-‘, strtolower($categoryname)); … Read more

Custom Taxonomies Terms as Post Title for Custom Post Types upon Publishing

I’ve pieced together a solution. Let me know if it’s what you need: add_filter(‘the_title’,’term_filter’,10,2); function term_filter($title, $post) { $post = get_post($post) ; if($post->post_type === ‘special_post_type’) { $terms = wp_get_object_terms($post->ID, ‘taxonomy’); if(!is_wp_error($terms) && !empty($terms)) { $title = $terms[0]->name; } } return $title; } Basically, I’m using a filter for the title that checks what post type … Read more

Return only the custom sub-term for custom post type, do not echo term-parent

Here’s more of a complete guide based on the $wp_query object: The Taxonomy First you might want to know in which taxonomy you are, what its name is and retrieve all its available data from the object. // Taxonomy name $taxonomy = get_query_var( ‘taxonomy’ ); // Taxonomy object get_taxonomy( $taxonomy ); // Taxonomy name get_taxonomy( … Read more

WordPress – Creating multiple versions of the same single-customtype.php depending on selected taxonomy categories

Okay, the following code should do the trick for you: function get_clients_correct_template($single_template) { global $post; if ( ‘clients’ == $post->post_type ) { $_template = false; // Get all the terms for this post $categories = wp_get_post_terms( $post->ID, ‘clients_categories’ ); if ( $categories && ! is_wp_error( $categories ) ) { global $wp; // I guessed that … Read more

Display child taxonomy until the last child

Got some ideas for your requirement. Check below code… $parent=get_queried_object()->term_id; $child = get_categories(‘child_of=”.$parent. “&hide_empty=0&echo=0&taxonomy=custom_taxonomy’); if(count($child)>0){ $i=0; foreach ( $child as $row ) { $i++; echo ‘<li><a href=”‘.get_term_link($row,$row->taxonomy).'”>’.$row->name.'</a></li>’; if(count($child)==$i){ $args=array( ‘post_type’ => ‘custom_post’,’order’ => ‘DESC’, ‘posts_per_page’=>1,’tax_query’ => array( array(‘taxonomy’ => ‘custom_taxonomy’,’terms’ =>$row->term_id, ‘field’ => ‘id’ )) ); $second_query = new WP_Query( $args ); if ($second_query->have_posts()) : … Read more