Child Terms not Displaying on the Taxonomy Term Admin Screen

I’ve encountered this kind of problem when i was building some front end post / term creation form. The number oh the ‘Right Now’ dashboard shows the right number of term, but the new term doesn’t shows up in the taxonomy admin screen. The solution: delete_option(‘taxonomy-name_children’); where ‘taxonomy-name’ is the name of the taxonomy. Hope … Read more

Exclude custom taxonomy from search results and archive pages

Copy the following snippet and paste it into the code of your theme, preferably in the functions.php file: /* Exclude a Category from Search Results */ add_filter( ‘pre_get_posts’ , ‘search_exc_cats’ ); function search_exc_cats( $query ) { if( $query->is_admin ) return $query; if( $query->is_search ) { $query->set( ‘category__not_in’ , array( 30 ) ); // Cat ID … Read more

get_terms() How many is TOO many?

Ad slowing down) Lame answer: depends on your server and stuff. Ad possible bug) wp_count_terms(); is a level “above” get_terms(); and therefore has values like ‘hide_empty’ and ‘fields’ already set. I’d say: diff your $args against those predefinied by wp_count_term();. The later function does nothing than calling the get_terms() at it’s end.

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

List Hierarchical Term List with Count with Related Term

I’ve done something like this in the Query Multiple Taxonomies plugin: https://github.com/scribu/wp-query-multiple-taxonomies/blob/master/core.php The good news is that it’s a generic solution: it works for any combination of posts and taxonomies. The bad news is that it might take some effort to figure out how it’s done.

Taxonomy terms sort by… Last name!

You can try the MySQL function SUBSTRING_INDEX() within the get_terms_orderby filter: /** * Order by the last word in the term name * @link https://wordpress.stackexchange.com/a/195039/26350 */ add_filter( ‘get_terms_orderby’, function( $orderby, $args ) { if( isset( $args[‘orderby’] ) && ‘wpse_last_word’ === $args[‘orderby’] ) $orderby = ” SUBSTRING_INDEX( t.name, ‘ ‘, -1 ) “; return $orderby; }, … Read more

wp_set_object_terms() — prevent overwrite?

wp_set_object_terms() has a fourth argument called append. Setting that to true during the call should add the term without unsetting the already set terms. wp_set_object_terms( $post_id, ‘add_this_term’, ‘in_this_taxonomy’, true);