[Resolved] Menu title showing as ‘array’ for menu

Home Forums Support [Resolved] Menu title showing as ‘array’ for menu

Home Forums Support Menu title showing as ‘array’ for menu

  • This topic has 5 replies, 2 voices, and was last updated 3 months ago by David.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2213991
    William

    Hi there,

    A while back GP support helped with making the category appear in the mobile menu for my website with this code:

    add_filter( 'option_generate_secondary_nav_settings', function( $settings ) {
        $category = get_the_category();
    
        if ( $category ) {
            $settings['secondary_nav_mobile_label'] = 'Explore ' . $category[0]->cat_name;
        }
    
        return $settings;
    } );

    This made something appear such as this:

    I have a different type of post format (glossary) which has ‘glossary-categories’ which I want to appear in the menu too. For example, this post should show up as ‘Explore Harry Potter’ where ‘Harry Potter’ is the glossary-category, but it currently shows as an array:

    What would I need to do so this appears as ‘Explore Harry Potter’ instead of ‘Explore Array’?

    Kind regards,

    Will

    #2214010
    David
    Staff
    Customer Support

    Hi there,

    is glossary-categories a Custom Taxonomy ?

    #2214048
    William

    I believe so, it is with the CM Glossary Tooltip plugin which creates a ‘glossary’ posts, ‘glossary-categories’ categories etc.

    #2214100
    David
    Staff
    Customer Support

    OK you should be able to do this:

    add_filter( 'option_generate_secondary_nav_settings', function( $settings ) {
        global $post;
        if ( 'glossary' === get_post_type() ) {
            $first_term = get_the_terms( $post->ID, 'glossary-categories' );
        } else {
            $first_term = get_the_category();
        }
        if ( $first_term ) {
            $settings['secondary_nav_mobile_label'] = 'Explore ' . $first_term[0]->name;
        }
    
        return $settings;
    } );
    

    It first checks if the post type is glossary and if so load the $first_term from the glossary-categories custom taxonomy. If not get the category as usual.

    #2214927
    William

    Incredible, thank you so much!

    #2214928
    David
    Staff
    Customer Support

    Awesome – glad to be of help!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.