Problem is that you’d need to pass a $post->ID
in order to not return false.
Better use is_object_in_taxonomy($object_type, $taxonomy)
and fill both the term and the tax in the function. It returns (boolean)
, so simply add your class based on the result:
echo $class = is_object_in_taxonomy( 'news', 'your_taxonomy' ) ? 'current-whatever' : '';
// or: (simplified for readabilities sake:
// set empty and override only in case.
// So you avoid dropping errors if the condition was not met and $current not set.
$class="";
if ( is_object_in_taxonomy( 'news', 'your_taxonomy' ) )
echo $class="current-whatever";
Related Posts:
- Taxonomy menu with post count and multiple parents
- Taxonomy slug by term ID
- Custom taxonomy position in admin panel
- Custom metabox for menu administration page?
- How to display submenus on page based on referring top-level parent?
- Remove pagination from WooCommerce product categories on admin edit navigation menus
- How to dynamically add custom taxonomy terms as a sub-menu of an existing menu item, using custom walker class
- Recreating the hierarchy of taxonomies for a dropdown form menu?
- Date range filter for manage posts list on edit.php
- Get custom category image from menu
- add taxonomy as one of menu items
- Controlling Taxonomy Category listings to hide and unhide specifics
- Hide product categories and taxonomy terms in menu if empty
- How to add Post Format Taxonomy Archive page in the menu?
- How to get all taxonomies which can be added in menu?
- Customizing Primary Menu to include custom taxonomy description
- How to Display a menu only if it has Posts in Custom Menu?
- When filtering query on custom taxonomy; main menu dissapears
- Adding a custom taxonomy to “nav_menu_item”
- Corrupted nav-menu?
- Can I output a custom taxonomy as a submenu in the site navigation menu?
- Add A CSS Class To A Menu Item When A Custom Taxonomy Term is Present On Single Post
- custom taxonomies menu
- How to add all existing Custom Taxonomy to Admin Menu Creations Interface?
- WordPress Main Menu with dynamic url
- Get the original menu item name string instead of the label
- What is the current page’s Taxonomy?
- How to looping taxonomy terms?
- How do I get the top-level terms in a custom taxonomy?
- Get only the first term by taxonomy
- Extend walker class with custom post types [closed]
- Is it possible to get a Previous/Next Taxonomy term archive URL?
- Which template name to use for taxonomies but not their terms?
- How to include parent terms in hierarchical taxonomy URLs?
- How to edit/remove a term that’s in multiple taxonomies?
- Fix : Custom Taxonomy Duplicating in each call
- Create Admin Only Taxonomies?
- Text and image in taxonomy page
- Custom taxonomies
- How to add custom field to custom taxonomy in 4.4
- Extending wordpress search to include excerpts and taxonomies?
- Adding ‘active’ class to custom taxonomies using walker in functions.php
- How to create custom taxonomy URLs without taxonomy name?
- How to insert an array of terms using wp_insert_term?
- Create Advanced search with taxonomies (not filter list)
- Show nav link highlighted
- display taxonomy slug from term ID
- How can i retrieve all custom registered taxonomy?
- Redirect all child taxonomy to its parent
- How to add taxonomy to user?
- How to use get_the_terms() to display multiple terms?
- List posts of term on term’s admin edit page
- quey posts from different categories with taxonomy
- Get number of post who belongs in two taxonomies!
- Checkbox onclick filtering on the same page
- Get parent and children taxonomy in different dropbox
- Problems with taxonomy quick edit box
- Adding custom taxonomy in my existing category URL
- single_cat_title equivalent for custom taxonomy?
- WP Multisite: Are custom taxonomies specific to each site only?
- My taxonomy won’t be registered. Can’t see it in my back-end
- Make child taxonomy categories use a set template
- How to customize taxonomy archive template files for subterms?
- Query posts using custom taxonomy and selected terms
- Foreach loop duplicating a taxonomy thumbnail image
- Output all terms in a custom taxonomy and add a “active” class only to the ones attached to the current post
- one post per term taxonomy
- How can I change the output display of my pagination?
- Custom permalink accept any params
- Terms change id after importing
- Hide custom taxonomy from easy admin
- how to use tax_query to apply both terms or one if one is empty
- Get current page term title to use in WP_Query
- Show related posts on single.php, grouped by taxonomy terms, with Advanced Custom Field post object selected
- making an index from custom taxonomies and tags of posts (not hierarchical taxonomy)
- Displaying my custom taxonomies in a using the_term_list()
- Using Custom Taxonomies to organise products – struggling to call a correct list
- Use wp_list_categories to list parent categories from actual term
- is there a way of getting term children that only shows those from two taxonomies
- How to add a dynamic dropdown derived from custom taxonomy
- Order get_terms by count using a custom taxonomy hierarchy
- How to create a non removable taxonomy term?
- How to show category list in WordPress
- custom taxonomy not showing up after adding capabilities upon updating to WP 5.1.1
- transfer two existing taxonomy terms into one custom metabox
- Catchable fatal error: Object of class WP_Error
- Permalink structure not working with Custom Taxonomy (URL like ./taxonomy/category/postname)
- Creating a Taxonomy Page [duplicate]
- WordPress shortcode Issue!
- Extra fields on categories that is available via the WP-API?
- Tax Query not working
- Taxonomy archive page have no post
- What’s the proper WordPress URL for the template of my custom taxonomy?
- WordPress show posts from children terms of a taxonomy term
- how to import custom taxonomy (& terms)
- How to create a page that lists custom taxonomies with links?
- Getting taxonomies specific to categories
- How to add/enqueue Custom CSS for a custom taxonomy page?
- wp_add_object_terms cant recognize a post ID
- Foreach for get_the_terms for hierarchical taxonomy don’t repeat Top Level Terms if contains multiple Second Level Terms