Taxonomies in URL

I recently talked about this at a couple of WordCamps. Here’s my talk from WC Portland, and the slides, source code, etc. Check out Recipe #2 specifically. First off, you should probably have a static prefix to start the URLs. It’s not 100% necessary, but without it your rewrite will conflict with page permalinks. If … Read more

Display post taxonomies tree

What about: $taxName = “tvr_amenity”; $terms = get_terms($taxName,array(‘parent’ => 0)); foreach($terms as $term) { echo ‘<a href=”‘.get_term_link($term->slug,$taxName).'”>’.$term->name.'</a>’; $term_children = get_term_children($term->term_id,$taxName); echo ‘<ul>’; foreach($term_children as $term_child_id) { $term_child = get_term_by(‘id’,$term_child_id,$taxName); echo ‘<li><a href=”‘ . get_term_link( $term_child->name, $taxName ) . ‘”>’ . $term_child->name . ‘</a></li>’; } echo ‘</ul>’; }

Custom Taxonomy – Tags Metabox is showing instead of Categories

You need to set hierarchical argument of your taxonomy to true (by default it’s false): function product_category_taxonomy() { $labels = array( ‘name’ => __( ‘Product Categories’ ), ‘singular_name’ => __( ‘Product Category’ ), ‘search_items’ => __( ‘Search Product Categories’ ), ‘all_items’ => __( ‘All Product Categories’ ), ‘parent_item’ => __( ‘Parent Product Category’ ), ‘parent_item_colon’ … Read more

pre_get_posts Tax Query not working for custom author page

Don’t run a new query in the template, modify the main query before it’s run via the pre_get_posts action in the theme’s functions.php file. function wpd_author_query( $query ) { if ( $query->is_author() && $query->is_main_query() ) { // your code to set $current_user_name here $query->set( ‘meta_key’, ‘_writer_relation_added_date_’ . $current_user_name ); $query->set( ‘orderby’, ‘meta_value_num’ ); $tax_query = … Read more

How to order a list of taxonomy terms alphabetically?

I found an answer to this at https://wordpress.stackexchange.com/a/105079/40536 I modified my code to the following: <form action=”<?php bloginfo(‘url’); ?>/” method=”get”> <?php $term_id = 279; $taxonomy_name=”categories”; $termchildren = get_term_children( $term_id, $taxonomy_name ); $children = array(); foreach ($termchildren as $child) { $term = get_term_by( ‘id’, $child, $taxonomy_name ); $children[$term->name] = $term; } ksort($children); echo ‘<select name=”‘ . … Read more

Display only post types that are direct children of the current taxonomy

Did you try WP_Query? Using my knowledge and the WP_Query documentation, I did this: $args = array( ‘post_type’ => ‘my_post_type’, //change the post type here ‘post_status’ => ‘publish’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘my_category’, //change the taxonomy name here ‘field’ => ‘id’, ‘include_children’ => false, ‘terms’ => 10 //change the term id here ) … Read more

Set object terms not working on plugin activation

register_activation_hook is one-time only activation hook. It can be used for database structure creation, as example, that needs to fire only on plugin activation trigger. In order to set a custom taxonomy you need a hook that will fire not just once, but per every WordPress load. Such as init. Use add_action( ‘init’, ‘YOUR_CALLBACK’ ); … Read more