What it says on the tin, really. I’m building my own Walker, and I usually like to look at the default state to get the lay of the land.
I’m calling the walker with wp_nav_menu
like this:
wp_nav_menu(array(
'menu' => 'primary-menu',
'container' => false,
'items_wrap' => '%3$s',
'walker' => new Demo_Nav_Walker(),
));
And the walker class looks like this:
class Demo_Nav_Walker extends Walker_Nav_Menu {
public function start_el(&$output, $data_object, $depth = 0, $args = null, $current_object_id = 0) {
echo var_dump($current_object_id);
}
}
This results in each element showing int(0)
. Now, I’m positive that the elements do have IDs, because if we look at the $data_object
instead, there’s an ID for each element (which is a WP_Post object).
I’ve been trying to poke at why this might be, and it seems like the core of it is in the function the Walker class uses to call this function (this is in the display_elements
function in in the Walker class):
$this->start_el( $output, $element, $depth, ...array_values( $args ) )
If I’m reading it right, it just…isn’t passing an ID into that function at all, so we’re getting the fallback value of 0.
My question is…does anyone know why? It seems odd that start_el can take an element ID, but just isn’t set up to do so. Is this one of those functionalities that’s meant to be useful if someone was going to do something more complicated and override the display_elements
function?