Trying to create a menu with category terms as I read in the WP docs "Using Walker Manually":
$menu_items = get_categories();
$walk = new \Walker_Category();
print_r( $walk->walk( $menu_items, -1 ) );
I get this warning:
Notice: Undefined index: use_desc_for_title in /srv/www/my-site/current/web/wp/wp-includes/class-walker-category.php on line 114
What is the right way to use Walker_category class?
Trying to create a menu with category terms as I read in the WP docs "Using Walker Manually": https://codex.wordpress/Class_Reference/Walker
$menu_items = get_categories();
$walk = new \Walker_Category();
print_r( $walk->walk( $menu_items, -1 ) );
I get this warning:
Notice: Undefined index: use_desc_for_title in /srv/www/my-site/current/web/wp/wp-includes/class-walker-category.php on line 114
What is the right way to use Walker_category class?
Share Improve this question asked Jul 11, 2019 at 7:01 aitoraitor 7252 gold badges8 silver badges23 bronze badges1 Answer
Reset to default 2the Walker_Category class you are using requires 3 params in walk() method, the third param will be use_desc_for_title value (this is due to how Walker_Category::start_el() method is written).
In other words, to use the walk() method without generating a notice you should change your last line to
print_r( $walk->walk( $menu_items, -1, -1 ) );
The third param is a boolean:
- "-1" (or false) - will remove the "title" attribute from the generated menu links
- "1" ( or true) - will make the menu use category description for the title attribute.