Get Bottom Most Level Taxonomy Terms?

Here is the solution I ended up with. This may help others too. $taxonomy = “product-category”; $args = array( ‘taxonomy’ => $taxonomy, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘hierarchical’ => true, ‘hide_empty’ => false, ); $the_query = new WP_Term_Query($args); $categories = $the_query->get_terms(); if ($categories){ foreach($categories as $category){ $ancestors = get_ancestors( $category->term_id, $taxonomy ); $category->ancestors = … Read more

Generic taxonomy-term template page

Simply use taxonomy-{taxonomy}.php. Refer to the Template Hierarchy Codex entry regarding taxonomies. WordPress will look for taxonomy template files in the following order: taxonomy-{taxonomy}-{term}.php – If the taxonomy were sometax, and taxonomy’s slug were someterm WordPress would look for taxonomy-sometax-someterm.php. taxonomy-{taxonomy}.php – If the taxonomy were sometax, WordPress would look for taxonomy-sometax.php taxonomy.php archive.php index.php … Read more

Filter taxonomy terms using multiple id in the edit-tags.php

It’s easy to implement. All you need is your own hook for get_terms_args filter: add_filter( ‘get_terms_args’, ‘wpse8170_get_terms_args’, 10, 2 ); function wpse8170_get_terms_args( $args, $taxonomies ) { if ( !in_array( ‘post_tag’, $taxonomies ) ) { return $args; } $matches = array(); if ( empty( $args[‘search’] ) || !preg_match( ‘/^\#(.*)$/’, $args[‘search’], $matches ) ) { return $args; … Read more

Category page only displaying the posts from a custom type

Ok I found a solution by following the recommandation of s_ha_dum to use pre_gets_posts. All the following code goes to functions.php 1 Create a new rewrite rule function rewrite_clean() { // my CPTs $types = array(‘projects’, ‘works’); foreach($types as $type) { add_rewrite_rule(‘^’.$type.’/([^/]*)/?$’, ‘index.php?post_type=”.$type.”&term=$matches[1]’,’top’); } } add_action(‘init’, ‘rewrite_clean’); transform the following format ?post_type=projects&term=architecture to the following … Read more

Display custom list of tags in post/page editor with hooks

We can override the Ajax call to wp_ajax_get_tagcloud() and do a clean hack. <?php /* Plugin Name: Custom Admin Tag Cloud */ add_action( ‘wp_ajax_get-tagcloud’, ‘ajax_tag_cloud_wpse_99497’, 1 ); function ajax_tag_cloud_wpse_99497() { // PASTE ALL THE MODIFIED FUNCTION HERE // http://core.trac.wordpress.org/browser/tags/3.5.1/wp-admin/includes/ajax-actions.php#L639 } Restore your core files to its original state, copy the modified function inside the above … Read more

When to use ‘get_category_by_path’ vs. ‘get_term_by’ to get category object from `get_query_var( ‘category_name’ )`?

You’re doing it correct @its_me. The latter, get_term_by() would be the best way, In my opinion , as I believe get_category_by_path uses get_term_by, just prepopulating the taxonomy to be category. Edit: As I mentioned in my comment, get_category_by_path is much less efficient, since it gets multiple terms,. and then compares the hierarchical path. get_term_by is … Read more