Better way to enforce category hierarchy in post_categories_metabox?
There’s a plugin written specifically to fix this ‘feature’ of WordPress, it’s called Category Checklist Tree. Despite the name, it works on custom taxonomies too.
There’s a plugin written specifically to fix this ‘feature’ of WordPress, it’s called Category Checklist Tree. Despite the name, it works on custom taxonomies too.
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
In WordPress 4.4 we will be able to use the long waited term meta so you might use that to store the extra info for your terms. The Term Meta API calls are: Add term meta: Function call: add_term_meta( $term_id, $meta_key, $meta_value, $unique ); Description: /** * Adds metadata to a term. * * @since … Read more
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.
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() 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);
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.
Use get_term() to get the name, slug, or description: $term = get_term( 1, ‘taxonomy_slug’ ); // Name echo $term->name; // Link echo get_term_link(1, ‘taxonomy_slug’); // OR echo get_term_link( $term );
You’re almost there mate. Try this though. <?php add_action(‘pre_get_posts’, ‘filter_press_tax’); function filter_press_tax( $query ){ if( $query->is_tax(‘press’) && $query->has_term(‘press’)): $query->set(‘posts_per_page’, 5); return; endif; } ?> You can use any conditional tag or any argument that can be passed to WP_Query to test your condition or set a new value via pre_get_posts. Also try $query->get(‘taxonomy’) / $query->get(‘term’). … Read more
I’d say your third option is the way to go. Incidentally, why did you roll your own static cache in taxonomy_image_plugin_get_associations() instead of using the built-in WP_Cache API for that? Is there a reason wp_cache_get wouldn’t work here? Seems like using the WP object cache would optimize better when people do have caching plugins turned … Read more