I believe that the problem is with this line:
$var = &$query->query_vars[$tax_slug];
- &$query is not necessary, simle $query should be enaught.
- $query->query->vars[$tax_slug] returns not an ID of term, but term’s slug
So
$term = get_term_by( 'id', $var, $tax_slug );
should be changed to
$term = get_term_by( 'slug', $var, $tax_slug );
But is not necessary as you want to get a slug.
Further, pay attention. “Category” and “Post tag” taxonomies are not present as “category” and “tag”, but are stored as “category_name” and “tag”, so you have to transform $tax_slug accordingly inside your foreach loop. Eg:
$tax_slug_original = $tax_slug;
if( $tax_slug == 'category' ){
$tax_slug = 'category_name';
}
if( $tax_slug == 'post_tag' ){
$tax_slug = 'tag';
}
$var = $query->query_vars[$tax_slug];
$tax_slug = $tax_slug_original;
Related Posts:
- Saving Taxonomy Terms
- How do I Filter Custom Post Type by Custom Taxonomy in the newest WordPress RESTful API?
- Filter get_categories() for taxonomy term in WordPress
- Ajax filter with custom taxonomies
- Filter posts with ajax form and checkboxes
- Highlight nav menu terms
- Help with issues on “Adding a Taxonomy Filter to Admin List for a Custom Post Type?”
- Want to filter only parent post in admin area
- What is better: Custom Fields vs Custom Taxonomies with Terms for perfomance, scalability and better user experience
- Custom Taxonomy breaking pages permalinks
- Filter custom post type archive page with custom taxonomies (categories) with AJAX
- How to query custom post types posts filtered by multiple custom taxonomies through a form selection
- Genesis filterable portfolio isotope [closed]
- How can I see a list of my Custom Post Types of the last term I was in?
- Displaying custom taxonomy in the admin list of a custom post type
- Categories of custom taxonomy don’t show any posts
- WordPress sort search results by custom order
- How to filter wp_list_categories output with some custom post type meta query?
- How to Filter custom post type by taxonomy?
- Filter term taxonomy metabox in custom post type
- How can I made custom taxonomies relationship?
- Sort and filter custom post type posts by custom taxonomy
- Filter posts by tax (dropdown) and meta value
- Only show posts with a specific term of an associated taxonomy in a custom post type archive
- REST filters only firing when I have a param set
- Custom Permalink For Custom Post Type – Working Fine But Broken For Pagination
- Store a value in global scope after init hook is fired
- Filter in Custom post type to find the parent post
- Insert custom taxonomy into category query
- Creating adminable dynamic filtering on custom post type
- Dropdown switching subcategories portfolio
- Exclude Custom Post Type from shared Custom Taxonomy
- Add Custom Taxonomy Terms as CSS Classes for CPT Posts in an Elementor Loop Item Template
- Check if post type has term
- How to remove Filters from post admin page?
- Custom taxonomy not showing up when adding a new custom post type
- query multiple taxonomies
- wp_set_object_terms() is not replacing term, but creating a new one
- Create an archive page for custom taxonomies
- Rewrite permalinks for custom posttype and custom taxonomy
- How to check if last uri segment is a custom post type or taxonomy term?
- Categories under custom post types doesn’t show properly
- Sort the main query in subcategories/terms?
- Custom Post Types, Custom Taxonomies and Permalinks ?
- get a list of posts from Custom Taxonomy
- Trying to manage templates on a blog with lots of custom taxonomies
- Display Custom Category (taxonomy) Name in Custom Post Type
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Order WordPress Custom Taxonomy Pages & Pagination Not Working
- Custom post type and taxonomy permalinks – Structure
- Best action hook to create custom post and assign taxonomy terms to it on plugin activation?
- Add html to cpt main page / admin edit.php
- Custom Post Types relationships
- How many Custom Post Types to register?
- How can i skip same post from taxonomy term?
- Set menu active state for custom posttype and category, given custom taxonomy term
- Custom post type structure for posts with multiple child posts
- List custom taxonomy specific to one custom post type
- Hide parent categories when clicked, and show it’s childs
- Get unique superset of taxonomy terms from a list of custom posts in another hierarchical taxonomy
- Auto Complete Search
- Filter Posts from the Main Query
- permalink /category/post-name with custom post type and taxonomy
- Displaying Custom Taxonomies From Multiple Custom Post Types
- Display and register custom categories for custom post types
- Properly flush rewrite rules on plugin activation
- Adding predefined terms to a taxonomy
- Redirect to archive is single post has a certain term assigned to it?
- Displaying tags associated with posts in Custom Post Type
- Custom taxonomy page returns 404
- portfolio custom type tags support
- Custom taxonomies to define versions of a product
- Targeting custom post type via functions.php doesn’t work
- How to define the template for custom posts?
- Displaying custom taxonomy menu in custom post type archive
- Custom post types templates
- prevent sub categories to show up
- Custom post type category link redirecting to 404 page
- Archive page URL for custom taxonomy and post type
- Custom Post Type Archive Page showing as 404
- Create custom post type categories
- Multiple Custom Post Type in Taxonomy Archive Causing White Screen
- Adding a Section for Visitors
- How to get post type archive category title
- Remove CPT Slug with 2 taxonomies and 1 post meta
- Add filter button to custom post type in admin area
- Should I make a taxonomy to organize data like this?
- Associate custom categories to different user IDs
- List all posts from custom post type by taxonomy
- archive-{custom_post_type}.php not getting recognized wordpress
- How to retrieve the permalink for a specific (custom) term?
- changing post type in loop query
- Taxonomy and Rewrite Structure
- Pagination for a Custom Taxonomy
- Trying to create hierarchy between 3-4 custom post types
- Custom Post Type Base URL
- Only One Post of Custom Post Type Appearing on Template Page
- Code to show related posts (custom post type and custom taxonomy/category) is messing with other code
- Dynamically count the number of custom post types associated to a custom taxonomy
- Add post id to url instead of WordPress default -2 suffix