Site logo

Archived topic

Menu title showing as 'array' for menu

5 replies · Started by William on May 9, 2022

Viewing posts 1–6 of 6

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

Hi there,

is glossary-categories a Custom Taxonomy ?

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

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.

Incredible, thank you so much!

Awesome - glad to be of help!

This archived topic is closed to new replies.