Order by slug in get_terms with multiple taxonomies
$keys = array_column($terms, ‘slug’); array_multisort($keys, SORT_ASC, $terms); That did the trick and let me sort terms in that muli array.
$keys = array_column($terms, ‘slug’); array_multisort($keys, SORT_ASC, $terms); That did the trick and let me sort terms in that muli array.
The edit-tags.php doesn’t listen to any arguments except the s search query variable. If you want to do anything more advanced, you will have to hook into the get_terms filter.
get_the_term_list() is retrieving the terms attached to the post that are in the taxonomy “types”. get_terms() is designed to retrieve all the terms within a taxonomy. What you are trying to do is use get_terms() for a specific term in a taxonomy, not a taxonomy itself. You need to do: $terms = get_terms(‘type’);
I’m not sure that there is a way to get it to use ‘OR’ instead of ‘AND’. Alternatively, you can do: $myquery[‘tax_query’] = array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘regions’, ‘terms’ => array(‘region1’), ‘field’ => ‘slug’, ‘operator’ => ‘IN’ ), array( ‘taxonomy’ => ‘population’, ‘terms’ => array(‘pop1’), ‘field’ => ‘slug’, ‘operator’ => ‘IN’ ), … Read more
Like Justin Tadlock says in your referenced article, the body_class() provides the ability to add classes dependant on the type of term. Given that you indicate your php knowledge is still growing; this maybe the best solution. The codex provides a list of classes on a body_class enabled: http://codex.wordpress.org/Function_Reference/body_class If that isn’t sufficient; wordpress has … Read more
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
It depends on what kind of type are the values from your $product_terms array. If you have strings there, like term slugs, then you probably want to check if $term->slug exists. If you have objects, then make sure the array is indexed, and not associative. For associative arrays use array_key_exists() instead.
get_term_by() just returns the first matching term, ‘first’ meaning some internal order in MySQL. If having multiple terms with the same name matters in your case, don’t rely on get_term_by() alone.
(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
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