Displaying terms by first letter

Try this code. <?php $taxonomy = ‘authors’;// e.g. post_tag, category $param_type=”authors”; // e.g. tag__in, category__in $term_args=array( ‘orderby’ => ‘name’, ‘order’ => ‘ASC’ ); $terms = get_terms($taxonomy,$term_args); if ($terms) { $first_letter = null; foreach( $terms as $term ) { $flag = 0; if( $first_letter != substr( $term->name, 0, 1 ) ) { $first_letter = substr( $term->name, … Read more

Display direct children of the current custom taxonomy in taxonomy.php template

See the Codex. The wp_list_categories allows you to set a child_of and a depth (in this case 1, we only want to go one level down). See the link to the Codex about styling it; there’s a whole host of options. <?php $term = get_queried_object(); wp_list_categories(array( ‘taxonomy’=>$term->taxonomy, ‘child_of’=>(int) $term->term_id, ‘hide_empty’=>0, ‘depth’=>1, )); ?> I’ve only … Read more

Show all posts without a custom taxonomy

If you use WP_Query‘s tax_query, you can set the operator to NOT IN and then just list your terms. The best way to do this (IMO) is to generate the tax query separately and dynamically, since all that will be changing in each of the different arguments is the slug/id of the category name. Your … Read more

Get Current Custom Taxonomy ID by Post ID

(Probably better to use get_the_terms). $terms = wp_get_object_terms( $pid, ‘custom_category’, array(‘fields’=>’ids’)); Get an array of term ids (will always been array, even if it is an array of one): $ids = wp_list_pluck( $terms, ‘term_id’ ); If you just want one id… then ‘pop’ out the last id: $id = array_pop($ids); See also PHP docs on … Read more

Only show posts from a certain category?

You need to modify your WP_Query loop. Add a tax_query argument to filter the category you want. $portfolioloop = new WP_Query(array( ‘paged’ => get_query_var(‘paged’), ‘post_type’ => ‘news’, ‘posts_per_page’ => 4, ‘tax_query’ => array( // Note: tax_query expects an array of arrays! array( ‘taxonomy’ => ‘portfolio’, // my guess ‘field’ => ‘id’, ‘terms’ => 51, ), … Read more

get_term_children doesn’t return an array of children terms

At first, try passing the Taxonomy as a string: $children = get_term_children($term->term_id, ‘locations’); The function get_category_children produces a string as return, so you can just echo it. the function get_term_children, however, returns an array. To see the contents of the array, try print_r( $children ); instead of echo. The last thing to keep in mind … Read more