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
- Filter for “get_post_type_archive_link()”
- Custom Taxonomy with Custom Post Type Finds No Posts
- Create permalink structure for one taxonomy archive per custom post type
- WordPress category, category post and single post
- Copy one CPT to another one in WordPress
- What’s the purpose of ‘taxonomies’ parameter in register_post_type()?
- How can I add programmatically custom taxonomy terms to a custom type post when saving posts?
- Define permalinks for custom post type by taxonomy in WP 3.4
- Disable single pages and archives and keep preview
- How to search from specific post type with tags?
- Custom Taxonomy not showing as option on custom post page
- how to get archive urls with same origin for custom types and terms?
- Custom Query to display posts with custom field
- Get taxonomy description based on variable
- Displaying Metabox value (custom post type taxonomy)
- multiple url slug for single custom post type
- Pretty URLs for Custom Post Type & Custom Taxonomy with Duplicate Slugs on WPML
- Filter by custom taxonomy slug on a custom post type
- Create 3 Level Relations with ACF and WordPress
- Archive page for taxonomy terms
- Add custom taxonomy to post content body?
- Limit amount of posts made within a custom taxonomy
- Issue on Creating Custom Tax Term Dynamically From Another CPT Meta-box On Publish
- Custom post type and taxonomy permalinks
- Exclude custom taxonomy term posts from custom post loop
- Only show posts with date of today or in the future (i.e don’t show past posts)?
- Rename a slug label
- Dynamically insert an article at the top of a taxonomy archive – or?
- Migrating Hierarchal Taxonomy Categories Between Post Types
- how to retain the ability to modify the post slug after applying a post_type_link filter?
- Custom Taxonomy dont save in a frontend form for post a custom post
- Query Custom Post by taxonomy multiple categories
- show most viewed posts of last days by link?
- Advanced archive url structure (category, tag and date)
- Setup page template array in a custom post type
- Change Dropdown jQuery to show/hide but with default place holder that shows all
- Get Posts List of Current Selected Custom Taxonomy in Shortcode
- Custom taxonomy terms as children of multiple custom post types
- Custom Taxonomy and Categories
- custom taxonomy pagination 404 error
- Get the taxonomy value in the post loop inside the archive page
- Excluded Custom Taxonomy Term Posts Displaying in loop
- pricefilter without WooCommerce
- Listing all custom posts having a specific taxonomy whatever the terms
- Create a Hierarchical List of Custom Taxonomies AND Posts
- Previous/Next custom post links within custom taxonomy
- Making permalink for custom post type/custom taxonomy. Stuck with 404 in the single post
- Custom Taxonomy page redirecting to 404 page
- Pretty permalink structure with multiple (AND OR) taxonomies
- Filter a custom taxonomy from displaying a button all other taxonomies can show
- Override “Parent” input for custom taxonomy
- Problem with type plugin and custom taxonomies
- Custom post type with Filter and Page Nav
- WordPress Custom taxonomy template
- Custom post type – two taxonomies
- Why is this custom post type defaulting to archive.php?
- Diffrent search templates for different post types
- Check if taxonomy is attached to at least one post in a post-type
- Getting (Invalid) when adding custom taxonomy of custom post type link in menu [closed]
- Display custom taxonomy posts of custom post types
- Looping taxonomy in taxonomy?
- Custom Post type as Taxonomy
- Get X posts with the same terms as the current post (custom post type and custom taxonomy)
- Trying to set up a range filter for related custom post types
- Custom fields disappearing when a custom post type is assigned
- Search for portfolio tags & mixing portfoliotags and post tags
- Add body class to custom post type