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
- How to Filter the Custom term loop based on dropdown
- Show a Category X’s custom post type on Category X archive page?
- How do I associate a custom post type with another through a taxonomy or storing an ID in a custom field?
- Get Taxonomy Term Title by it’s URL
- Add custom taxonomy to post content body?
- custom taxonamy and post type
- Taxonomy custom post type URL
- Display as tree terms of taxonomy and custom posts for each term of taxonomy
- How to add a post slug to a url?
- Second Set of Eyes: One custom taxonomy shows in Appearance > Menus, one does not
- Custom post type url with category
- Custom Taxonomy terms aren’t getting referenced or saved in Quick Edit or Bulk Edit, only on Single product page?
- How do I move/order posts with a tag to the end?
- Adding custom post category slug in permalink causes 404 error for pages and posts
- Add custom image size for custom post type or taxonomy
- Get taxonomy values based on wp_query results
- Display post as term id
- Ajax Custom Post Filter is not filtering
- Need Output Custom Taxonomy from Custom Post Type
- Display all taxonomy terms, add class if term applies to current post
- Custom Post Type – No Results Found
- Return the latest post from a custom Taxonomy and Post Type
- Cannot add category or custom taxonomy from admin. WordPress site is hosted in Windows 16 server via IIS. No XAMPP or WAMP
- Don’t know how to show custom taxonomies from a custom post_type
- 404 error when navigating to a taxonomy page with Cyrillic, what’s wrong?
- Custom taxonomy rewrite give pagination 404
- How to duplicate entire custom post type
- Displaying CPT and custom taxonomy side by side in Bootstrap 4 component
- Use Custom Post Type archive page for the taxonomies term archive page
- How Can I Change the Custom Post Type Slug to the Taxonomy Slug in the URL?
- Is it possible to have dedicated page for parent/child taxonomy?
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- Can a Custom Taxonomy be named “category” like normal Posts?
- How to use terms from the same custom taxonomy in different roles in a custom post type?
- How to have the same url structure for both a CPT and a Taxonomy?
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- create a subcatagory for a custom post type and out put url as posttype/subcategory/item
- How do I display the taxonomy term alongside the post type post title?
- Display custom post type category, while in a CPT category, then the posts beneath
- Why are taxonomy terms not saving when using custom meta boxes with radio button taxonomy selectors?
- Display Custom Toxonomy In WordPress and theme Widgets category selection dropdown list
- Hide parent categories when clicked, and show it’s childs
- WP_Query inside foreach loop returning same value for all options when filtered using ajax
- Hide post navigation if current post is in a category with only one post
- Get related posts of child term of custom post type
- Limit amount of posts made within a custom taxonomy
- custom-taxonomy/post_name instead of the default post_type/post_name
- Show custom post archive when custom post not specified
- Show custom post type relationships by taxonomy
- Group CPT posts by custom taxonomy
- Issue on Creating Custom Tax Term Dynamically From Another CPT Meta-box On Publish
- Filter CPT posts by one or more categories
- Custom taxonomy and custom post type – wrong permalinks and template
- Setting up taxonomy to relate various custom post types – advice on structuring?
- Getting categories of posts under a custom taxonomy
- creat filter with wp_query
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- Post count by month of taxonmy term
- How can I make the slug of the taxonomy also the slug of the custom post
- Query taxonomy of taxonomy of custom post type
- Taxonomies don’t show up on in the dashboard page for a custom post type in wordpress 5.22
- Can’t remove front from permalinks for custom taxonomy category page
- Custom WP Query on custom meta and sort by multiple meta keys value
- How to checked selected category checkbox when my custom post inserted from frontend
- Allow duplicate slugs for custom post type with taxonomies
- list taxonomies from a custom post type
- How to display Custom Taxonomy under Custom Admin Menu?