• Resolved bret.miller

    (@bretmiller)


    My theme is calling wp_nav_menu() without parameters. When using custom post types with custom taxonomy, it crashes in /wp-includes/nav-menu-template.php on line 353. After a bit of debugging, this line:

    $terms = wp_get_object_terms( $queried_object_id, $taxonomy, array( ‘fields’ => ‘ids’ ) );

    is returning an array of WP_Term objects instead of an array of numeric ids.

    I am not sure how to fix the source of the problem, but I worked around it by modifying nav-menu-template.php to check if the type returned is object and get the term_id from the object instead. It is not a good solution and it will stop working probably the next time WordPress updates.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I cannot replicate your experience. Line 353 should always return an array of IDs. If that is not happening, it’s likely your theme or a plugin is altering the function’s args to cause this problem.

    Confirm by deactivating all plugins and switching to a default theme, preferably 2021 or earlier (non-block or classic themes). Temporarily alter the theme’s wp_nav_menu() call to not use any args. Temporarily add your custom post and taxonomy registration code to functions.php.

    You should no longer get any errors, line 353 should always return IDs. To identify which module was altering function args, restore your normal plugins, then theme, one at a time, testing after each. When the problem recurs, the last activated is the cause. Of course, where applicable, when you restore whichever plugin registers custom post and taxonomy, remove the same registration code from the temporary code in functions.php.

    Thread Starter bret.miller

    (@bretmiller)

    OK… I found an odd taxonomy/term filter in the functions.php for the theme. Based on other code by the developer, my guess is he copied it from another project without any understanding of why it was there or what it did. But removing it did fix the problem so you were correct. It was not WordPress.

    Thank you for your pointers for tracking down the issue.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_nav_menu crashing in PHP 8.2 with custom taxomy’ is closed to new replies.