List of post categories only associated to another custom taxonomy

Here’s what I come up with, looks like it’s working. But maybe (surely) there’s a more efficient way to do the same: // current queried $term = ‘sector’; $current_sector_id = get_queried_object_id(); // Prepare wp_query to get all posts assigned to the current “sector” $sector_posts_query = new WP_Query(); $sector_posts_query->query( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1, … Read more

Display a list of random terms from custom taxonomy with shortcode

Try this code: function these_rand_tax1() { $max = 8; //number of categories to display $taxonomy = ‘baumaschinen_cat’; $terms = get_terms(‘taxonomy=’ . $taxonomy . ‘&orderby=name&order=ASC&hide_empty=0’); $terms = (array)$terms; // Random order shuffle($terms); // Get first $max items $terms = array_slice($terms, 0, $max); // Sort by name usort($terms, function ($a, $b) { return strcasecmp($a->name, $b->name); }); // … Read more