0

Trying to create a menu with category terms as I read in the WP docs "Using Walker Manually": https://codex.wordpress.org/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.com/current/web/wp/wp-includes/class-walker-category.php on line 114

What is the right way to use Walker_category class?

1 Answer 1

2

the 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.