get_terms orderby name as numbers

I know this post is very old but still answering for others who reach here. Following is a very simple filter to sort the terms as numbers. You only need to set the variable $taxonomy_to_sort with taxonomy slug and place it in functions.php of your theme. add_filter( ‘get_terms_orderby’, ‘terms_order_as_number’, 10, 3); function terms_order_as_number($order_by, $args, $taxonomies){ … Read more

Echo custom taxonomy term name

I managed to solve this and I will post the answer: <?php $args = array(‘number’ => ‘1’,); $terms = get_terms(‘recipes’, $args ); foreach( $terms as $term ){ echo ‘<div class=”title”>’ . $term->name . ‘recipe</div>’; }

Get the terms of a custom taxonomy for a specific author in author template

First get a list of the author posts then loop over the each post and get the terms used ex: function list_author_used_terms($author_id){ // get the author’s posts $posts = get_posts( array(‘post_type’ => ‘custom_post_type_name’, ‘posts_per_page’ => -1, ‘author’ => $author_id) ); $author_terms = array(); //loop over the posts and collect the terms foreach ($posts as $p) … Read more

List only first-level children of specific custom taxonomy term

First of all you need the term id of hydro term, you can retrive it using get_term_by $hydro = get_term_by(‘slug’, ‘hydro’, ‘product_cat’); After that, you can use the term id as ‘parent’ argument for get_terms $hydro_children = get_terms( ‘product_cat’, array( ‘parent’ => $hydro->term_id ) ); Now you can display a list of this children: if … Read more

Automatically assign taxonomy term if custom meta value exists

You should hook onto the save_post action. add_action( ‘save_post’, ‘add_video_taxonomy’ ); function add_video_taxonomy( $post_id ) { // you should check if the current user can do this, probably against publish_posts // you should also have a nonce check here as well if( get_post_meta( $post_id, ‘video_url’, true ) ) { wp_set_post_terms( $post_id, ‘video’, ‘your_custom_taxonomy_name’, true ); … Read more

How do I get taxonomy terms by ID in a specific order

get_terms does not support a post__in argument and I don’t see any other argument that will let you force an order. You can, however, accomplish this with one fof at least two filters: function gto_forced_order($orderby) { $orderby = “FIELD(t.term_id,5,1,4)”; return $orderby; } add_filter(‘get_terms_orderby’,’gto_forced_order’); $terms = get_terms(‘category’); var_dump($terms); Or… function gto_forced_order($pieces) { $pieces[‘orderby’] = “ORDER BY … Read more

Get multiple term objects by ids

I wonder if you mean something like this modified Codex example: // Fetch: $terms = get_terms( ‘category’, array( ‘include’ => array( 1, 2, 3 ), ) ); // Output: if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { $li = ”; foreach ( $terms as $term ) { $li .= sprintf( … Read more

What are terms and taxonomy, how they related to post and how these three are stored in database?

What are the terms and taxonomy in wordpress? From WordPress.org’s Taxonomy Codex… In WordPress, a “taxonomy” is a grouping mechanism for some posts (or links or custom post types)… The names for the different groupings in a taxonomy are called terms. Using groupings of animals as an example, we might call one group “birds”, and … Read more