WP_Query use for a filter with multiple Taxonomies and Terms

Try this way: $args = array( ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post_status’ => ‘publish’ ); if ( isset( $_POST[‘typefilter’] ) && $_POST[‘typefilter’] !== ” ) { $args[‘post_type’] = ‘post_type_x’; $args[‘tax_query’][0][‘taxonomy’] = ‘type_emp’; $args[‘tax_query’][0][‘field’] = ‘id’; $args[‘tax_query’][0][‘terms’] = $_POST[‘typefilter’]; $args[‘tax_query’][0][‘operator’] = ‘IN’; } if ( $_POST[‘typefilter’] == ”) { $args[‘post_type’] = ‘post_type_x’; } // If … Read more

deleting terms programmatically

You can use below to assign all posts to another term during deletion mentioned on same page.. “The $args ‘force_default’ will force the term supplied as default to be assigned even if the object was not going to be termless.” Other wise if there was only one term attached with post, post becomes term less.

get_terms with more than x post count

Give: $terms = get_terms(“my_taxonomy”); $count = count($terms); if ( $count > 0 ){ echo “<ul>”; foreach ( $terms as $term ) { if ($term->count > 2) { echo “<li>” . $term->name . “</li>”; } } echo “</ul>”; } a shot. It will grab all the terms and then run a check to see if the … Read more

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