wp_insert_term doesn’t work with custom post type’s taxonomy
try init instead of after_setup_theme function example_insert_category() { wp_insert_term( ‘Example Category’, ‘friendsof’ ); } add_action( ‘init’, ‘example_insert_category’ );
try init instead of after_setup_theme function example_insert_category() { wp_insert_term( ‘Example Category’, ‘friendsof’ ); } add_action( ‘init’, ‘example_insert_category’ );
Use the terms_clauses filter, which passes all the various components of the query (fields, join, where, orderby, order & limits), and implement your own “search” argument: function wpse_178511_get_terms_fields( $clauses, $taxonomies, $args ) { if ( ! empty( $args[‘surname’] ) ) { global $wpdb; $surname_like = $wpdb->esc_like( $args[‘surname’] ); if ( ! isset( $clauses[‘where’] ) ) … Read more
Not directly, but I have a need for this functionality as well, as part of a plugin I’m writing for a client and have what I think is a pretty good start on an implementation. The approach I’m taking is to store a term meta when the term is disabled and then to hook into … Read more
You can get terms, from multiple slugs, with the slug argument: $exclude = get_terms ( [ ‘slug’ => [ ‘president’, ‘vice-president’, ‘admin’, ‘rnd’ ], ‘taxonomy’ => $cat_type, ‘fields’ => ‘ids’, ] ); where we use the fields argument to return only term ids.
I don’t have a solution, but there’s a ticket #20541 on Make WordPress Core. Apparently a call to switch_to_blog() would not repopulate $wp_taxomies, which these taxonomies rely on.
Still looking myself. After some exploring I decided to use the Term Menu Order plugin by @jameslafferty. This will add menu_order to the terms table and can be used across taxonomies and templates. @TheDeadMedic seems to have enhanced this functionality over here, discussing a similar issue.
This should get you the names of all such terms in an array $wpdb->get_col(“SELECT DISTINCT {$wpdb->terms}.name FROM {$wpdb->terms} INNER JOIN {$wpdb->term_taxonomy} ON {$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id INNER JOIN {$wpdb->term_relationships} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id WHERE {$wpdb->term_taxonomy}.taxonomy = ‘shape’ AND {$wpdb->term_relationships}.object_id IN ( SELECT object_id FROM {$wpdb->term_relationships} INNER JOIN {$wpdb->term_taxonomy} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id WHERE {$wpdb->term_taxonomy}.taxonomy = ‘color’ … Read more
I think you’re on the right track because wp_get_object_terms() can take an array of IDs for its first argument, it’s just that $wp_query is not the array you want. I can’t guarantee that this is more efficient (not my area of expertise), but I believe this [partially-tested] snippet would do what you want with at … Read more
Working off of Pieter Goosen’s answer to this question, the way around this is to create a list of all the categories except the one you want to exclude, then search for posts that include them. That way, if a post has the excluded category but also other categories, it’ll be included. So, in my … Read more
This is probably because your taxonomy is hierarchical, and the default meta box for such taxonomies is similar to the category box – which displays all terms as input elements. So the browser lag for thousands of elements within a page is expected in this case. If you can’t make your taxonomy non-hierarchical, try removing … Read more