Taxonomy count per Post type

I needed to get the number of post per type per term so i created this small function: function get_term_post_count_by_type($term,$taxonomy,$type){ $args = array( ‘fields’ =>’ids’, //we don’t really need all post data so just id wil do fine. ‘posts_per_page’ => -1, //-1 to get all post ‘post_type’ => $type, ‘tax_query’ => array( array( ‘taxonomy’ => … Read more

How to limit the number of terms (terms acts like categories)

number (integer) The maximum number of terms to return. Default is to return them all. http://codex.wordpress.org/Function_Reference/get_terms So… $terms = get_terms(‘new_category’,array(‘number’ => 5)); But there is a good chance that some of your terms will never show up. You will get the first five or the last five (in the example) depending on the sort order. … Read more

get term by id without taxonomy

Yes, but you need you make your own SQL query. A modified version of WP’s get_term(): function &get_term_by_id_only($term, $output = OBJECT, $filter=”raw”) { global $wpdb; $null = null; if ( empty($term) ) { $error = new WP_Error(‘invalid_term’, __(‘Empty Term’)); return $error; } if ( is_object($term) && empty($term->filter) ) { wp_cache_add($term->term_id, $term, ‘my_custom_queries’); $_term = $term; … Read more

Custom Taxonomy in Permalink of Post

Assuming your custom taxonomy is called artist (and you don’t override the slug in the rewrite parameter) you can use the rewrite tag %artist%. WordPress implements almost every functionality to use those rewrite tags in post permalinks. There are only a few small adaptations necessary. Building the Permalink First, you’ll need to use the post_link … Read more

Search custom taxonomy term by name

// We get a list taxonomies on the search box function get_tax_by_search($search_text){ $args = array( ‘taxonomy’ => array( ‘my_tax’ ), // taxonomy name ‘orderby’ => ‘id’, ‘order’ => ‘ASC’, ‘hide_empty’ => true, ‘fields’ => ‘all’, ‘name__like’ => $search_text ); $terms = get_terms( $args ); $count = count($terms); if($count > 0){ echo “<ul>”; foreach ($terms as … Read more

Why is my working Custom Taxonomy not in get_taxonomies array?

The Invalid Taxonomy error will be raised by the function get_terms(). You’re registring your taxonomy on the init action hook. Therefore you have to call your get_terms() function on the same or a later hook. Try this snippet. It should display all term names of your taxonomy, regardless if the term is empty. add_action(‘init’, ‘wpse29164_registerTaxonomy’); … Read more

Attaching Metadata to a Taxonomy Item

As Mamaduka said there is currently no (native) way of storing meta-data for taxonmies. There is talk of it. But it has stalled since its proving difficult to agree on how best to implement it. For large amounts of data you might not want to use the options table. Alternatively you can create your own … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)