Remove taxonomy slug from a custom hierarchical taxonomy permalink

UPDATE Since writing this WordPress core has added the ‘do_parse_request’ hook that allows URL routing to be handled elegantly and without the need to extend the WP class. I covered the topic in-depth in my 2014 Atlanta WordCamp talk entitled “Hardcore URL Routing“; the slides are available at the link. ORIGINAL ANSWER URL Design has … Read more

get_posts assigned to a specific custom taxonomy term, and not the term’s children

In looking at the WP_Tax_Query class in /wp-includes/taxonomy.php, I found that there is a ‘include_children’ option which defaults to true. I modified my original get_posts() call with the following, and it works great: $pages = get_posts(array( ‘post_type’ => ‘page’, ‘numberposts’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘taxonomy-name’, ‘field’ => ‘term_id’, ‘terms’ => 1, … Read more

How do I exclude a custom taxonomy from the post loop

You would want to use the NOT EXISTS operator along with passing the taxonomy slug, which tells the query not to include any of a chosen category from your custom taxonomy inside the loop. To exclude all posts that are in the taxonomy “fruit” (regardless of fruit kind), here is the snippet: $args = array( … Read more

“tax_query” parameter not working with WP_Query

The tax_query parameter is an array of arrays, not just an array. This: ‘tax_query’ => array( ‘taxonomy’ => ‘video_type’, ‘terms’ => ‘episode’, ‘field’ => ‘slug’, ‘include_children’ => true, ‘operator’ => ‘IN’ ), Should instead be this: ‘tax_query’ => array( array( ‘taxonomy’ => ‘video_type’, ‘terms’ => ‘episode’, ‘field’ => ‘slug’, ‘include_children’ => true, ‘operator’ => ‘IN’ … Read more

How to Add Custom Fields to a Custom Post Type?

This is probably more complicated than you think, I would look into using a framework: http://wpgear.org/#meta-fields If you want to write your own , here are some decent tutorials: http://net.tutsplus.com/tutorials/wordpress/creating-custom-fields-for-attachments-in-wordpress/ http://sltaylor.co.uk/blog/control-your-own-wordpress-custom-fields/ http://thinkvitamin.com/code/create-your-first-wordpress-custom-post-type/

Can multiple custom post types share a custom taxonomy?

Sharing a taxonomy between CPTs I would like to know if two custom content types can share one custom taxonomy. Simple said: Yes, they can. How to share You should always register custom taxonomies and post types to each other as early as possible. Wrap your registration process in a function, hooked to the init … Read more

Mixing custom post type and taxonomy rewrite structures?

You can always override the template that will be called with the template_include or a related filter, but this might hide deeper problems with custom archives. As I understand it, you want to use the following structure: /glossary/ should be an archive page for all sumo-glossary-term posts /glossary/[letter]/ should be an archive page for posts … Read more

List all posts in custom post type by taxonomy

Try this $custom_terms = get_terms(‘custom_taxonomy’); foreach($custom_terms as $custom_term) { wp_reset_query(); $args = array(‘post_type’ => ‘custom_post_type’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘custom_taxonomy’, ‘field’ => ‘slug’, ‘terms’ => $custom_term->slug, ), ), ); $loop = new WP_Query($args); if($loop->have_posts()) { echo ‘<h2>’.$custom_term->name.'</h2>’; while($loop->have_posts()) : $loop->the_post(); echo ‘<a href=”‘.get_permalink().'”>’.get_the_title().'</a><br>’; endwhile; } } We get all the terms of a … Read more