Show WordPress Custom Taxonomy Items Based On a Selected Item From Another Custom Taxonomy

Why not make the towns child terms of each state? The taxonomy could be location: See MikeSchinkel’s detailed q and a regarding hierarchal taxonomies. A more elegant solution than refreshing the page upon state selected would be to load the “thetown” child terms using ajax and the get_term_children function or the custom $wpdb query outlined … Read more

Select All in Parent Category, Group by Child Category?

Here’s a straight up simple solution. Requires you to have the most recent version of WordPress though. (or at least 4.1) Using nested taxonomy query. Taking what you have, and just adding to it a bit. $args = array( ‘post-type’ => ‘episode’, ‘post-status’ => ‘publish’, ‘posts_per_page’ => 4, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( … Read more

pre_get_posts with tax_query causes empty result

You use tax_query incorrectly. Take a look at Codex Page tax_query should be an array which can contain: relation – it should be string (AND/OR) taxonomy term – array with defined taxonomy, field, terms, and so on. In your code your setting tax_query to: $taxquery = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( array( ‘taxonomy’ … Read more

Pagination throws 404 error on custom taxonomy archive pages

This function fixed the issue: function change_posttype() { if( is_archive() && !is_admin() ) { set_query_var( ‘post_type’, array( ‘post’, ‘portfolio’ ) ); } } add_action( ‘parse_query’, ‘change_posttype’ ); Then I just removed the paged and query_string function in my code and just left the regular loop 🙂

Get second level terms of custom taxonomy

You can use PHP’s array_filter to process the results of a taxonomy query function that returns its results, and then display them. Something like: # This returns the whole taxonomy… $whole_tax = get_terms(‘customtax’, array(‘hide_empty’ => 0)); $second_level = array_filter($whole_tax, function ($t) { # This term has a parent, but its parent does not. return $t->parent … Read more

Can I turn off write-in tags/taxonomies?

Here is what I came up with, seems to work: add_filter( ‘pre_post_tags_input’, ‘no_tags_input_create’ ); add_filter( ‘pre_post_tax_input’, ‘no_tax_input_create’ ); function no_tags_input_create($tags_input) { $output = array(); foreach( $tags_input as $tag ) if( term_exists( $tag, ‘post_tag’) ) $output[] = $tag; return $output; } function no_tax_input_create($tax_input) { if( !isset($tax_input[‘post_tag’]) ) return $tax_input; $output = array(); $tags = explode(‘,’, $tax_input[‘post_tag’]); … Read more