Adding content to a taxonomy metabox

From core: function post_tags_meta_box($post, $box) { $defaults = array(‘taxonomy’ => ‘post_tag’); if ( !isset($box[‘args’]) || !is_array($box[‘args’]) ) $args = array(); else $args = $box[‘args’]; extract( wp_parse_args($args, $defaults), EXTR_SKIP ); $tax_name = esc_attr($taxonomy); $taxonomy = get_taxonomy($taxonomy); $disabled = !current_user_can($taxonomy->cap->assign_terms) ? ‘disabled=”disabled”‘ : ”; $comma = _x( ‘,’, ‘tag delimiter’ ); ?> <div class=”tagsdiv” id=”<?php echo $tax_name; … Read more

Checking return with WP Error

Not entirely sure what you are asking, but if I understand correctly you want to perform some testing on the return value in order to avoid iterating a WP_Error object and perhaps handle errors in some way. According to the documentation get_terms() will return an array of term objects or false if no objects were … Read more

get_category_parents for custom post type taxonomy

Updated answer: There’s now a core function since WordPress 4.8, to list the ancestors of a given term: get_term_parents_list( int $term_id, string $taxonomy, string|array $args = array() ) and get_category_parents() is a wrapper for that function with $taxonomy as ‘category’. Previous answer: Here is a modified version I made from the function get_category_parents() to support … Read more

Allow user to set custom order to a list of custom taxonomies?

For those interested I figured it out. I added this to my functions.php: function set_the_terms_in_order ( $terms, $id, $taxonomy ) { $terms = wp_cache_get( $id, “{$taxonomy}_relationships_sorted” ); if ( false === $terms ) { $terms = wp_get_object_terms( $id, $taxonomy, array( ‘orderby’ => ‘term_order’ ) ); wp_cache_add($id, $terms, $taxonomy . ‘_relationships_sorted’); } return $terms; } add_filter( … Read more

Getting Term ID from Term Name for WordPress Query

Check for variables names: $excludes=””; if($filtering_excludes) { $exclude_terms = explode(“, “, $filtering_excludes); foreach ($exclude_terms as $exclude_term) { $term = get_term_by( ‘name’, $exclude_term, $filtering_tax ); $exclude_term_array[] = $term->term_id; } $excludes= implode(“, “, $exclude_term_array); }

Customize my custom taxonomy table in Admin panel

This should do the trick: add_action( ‘admin_print_styles’, ‘cor_admin_print_styles’, 200 ); function cor_admin_print_styles() { $screen = get_current_screen(); if ( ‘edit-tags’ === $screen->base && ‘department’ === $screen->taxonomy ) { echo <<<EOF <style> .fixed .column-posts { width: auto; } .widefat .num, .column-comments, .column-links, .column-posts { text-align: left; } </style> EOF; } }

Show posts from two or more custom taxonomy terms

You need to combine two tax queries with and AND relation: $args = array( ‘posts_per_page’ => 10, // Number of posts per page ‘post_type’ => ‘classifieds’, // Custom Post Type like Movies ‘tax_query’ => array( ‘relation’ => ‘AND’ array( ‘taxonomy’ => ‘classifieds_tags’, //Custom Taxonomy Name like Genre ‘field’ => ‘slug’, ‘terms’ => array( ‘books’ //Tags … Read more