Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:20:50+00:00 2026-06-04T20:20:50+00:00

I have a custom post type and a custom taxonomy. Each custom post type

  • 0

I have a custom post type and a custom taxonomy. Each custom post type is assigned to exactly one term. I added a menu entry for each term in my custom taxonomy. Behind each of menu entries is a overview page with all the custom posts assigned to this term. If you click on one of the customs posts a details page opens. But if you are on a details page the corresponding menu entry for the taxonomy term is no longer marked as active. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:20:53+00:00Added an answer on June 4, 2026 at 8:20 pm

    Ok, I found the following solution for my problem:

    add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
    
    function special_nav_class($classes, $item) {
        global $naventries;
        $naventries[$item->ID] = $item;
        if($item->type == 'taxonomy') {
            global $post;
            $terms = get_the_terms($post->ID, $item->object);
    
            $currentTerms = array();
            if ( $terms && ! is_wp_error( $terms ) ) {
                foreach($terms as $term) {
                    $currentTerms[] = $term->slug;
                }
            }
    
            if(is_array($currentTerms) && count($currentTerms) > 0) {
                $currentTerm = get_term($item->object_id, $item->object);
                if(in_array($currentTerm->slug, $currentTerms)) {
                    $classes[] = 'current-menu-item';
                }
            }
        } 
    
         return $classes;
    }
    

    But there is still one problem left. I also want to add the class current-menu-ancestor to the parent element. I have the id of the parent element via $item->menu_item_parent but no idea how I can use this id to change the classes of the corresponding menu entry at this point?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have created a custom post type named Books & i have a widget
I've created a custom post type and a custom taxonomy to go with it.
I have a custom post type called song and i want to query the
I have a Custom Post Type and I am going to customize it to
I observed that if I have a custom post type called article, the links
I have created a custom post type of 'portfolio' and page with a template
I have setup a custom Post Type in WordPress and have a question. How
I have setup a custom post type in Wordpress. It is a section where
I have created a custom post type called banners and want to enable the
I have created a custom post type calles articles and a custom category like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.