WordPress – Creating multiple versions of the same single-customtype.php depending on selected taxonomy categories

Okay, the following code should do the trick for you: function get_clients_correct_template($single_template) { global $post; if ( ‘clients’ == $post->post_type ) { $_template = false; // Get all the terms for this post $categories = wp_get_post_terms( $post->ID, ‘clients_categories’ ); if ( $categories && ! is_wp_error( $categories ) ) { global $wp; // I guessed that … Read more

List Hierarchical Term List with Count with Related Term

I’ve done something like this in the Query Multiple Taxonomies plugin: https://github.com/scribu/wp-query-multiple-taxonomies/blob/master/core.php The good news is that it’s a generic solution: it works for any combination of posts and taxonomies. The bad news is that it might take some effort to figure out how it’s done.

Taxonomy terms sort by… Last name!

You can try the MySQL function SUBSTRING_INDEX() within the get_terms_orderby filter: /** * Order by the last word in the term name * @link https://wordpress.stackexchange.com/a/195039/26350 */ add_filter( ‘get_terms_orderby’, function( $orderby, $args ) { if( isset( $args[‘orderby’] ) && ‘wpse_last_word’ === $args[‘orderby’] ) $orderby = ” SUBSTRING_INDEX( t.name, ‘ ‘, -1 ) “; return $orderby; }, … Read more

wp_set_object_terms() — prevent overwrite?

wp_set_object_terms() has a fourth argument called append. Setting that to true during the call should add the term without unsetting the already set terms. wp_set_object_terms( $post_id, ‘add_this_term’, ‘in_this_taxonomy’, true);

get a specific taxonomy term name

Use get_term() to get the name, slug, or description: $term = get_term( 1, ‘taxonomy_slug’ ); // Name echo $term->name; // Link echo get_term_link(1, ‘taxonomy_slug’); // OR echo get_term_link( $term );

Using pre_get_posts to set posts per page, how do I?

You’re almost there mate. Try this though. <?php add_action(‘pre_get_posts’, ‘filter_press_tax’); function filter_press_tax( $query ){ if( $query->is_tax(‘press’) && $query->has_term(‘press’)): $query->set(‘posts_per_page’, 5); return; endif; } ?> You can use any conditional tag or any argument that can be passed to WP_Query to test your condition or set a new value via pre_get_posts. Also try $query->get(‘taxonomy’) / $query->get(‘term’). … Read more