• Uncaught TypeError: Cannot use ‘in’ operator to search for ‘length’ in

    I had this error on a WordPress website for a customer.

    Uncaught TypeError: Cannot use 'in' operator to search for 'length' in

    The error was related to the plugin WP Store Locator. The Store Locator wouldn’t load the locations and would only show one Google Maps marker. The code inspector pointed me to the admin-ajax.php file which was involved.

    The strange thing was that it does show the Store Locations to logged in users but would not show them to not logged in users!

    Screenshot WP Store Locator (when users are logged in)

    On the WP Store Locator support page there are more mentions of this error and it is indicated to be caused by either the cache plugin (mingling with the javascript/jquery files) or it is caused by (child) theme files (especially functions.php).

    • I tested deactivating the cache plugin (WP Rocket) with no result.
    • I tested the website with a clean TwentyTwenty theme and the error was gone.
    • I turned off the added functions in the functions.php of my (child) theme and the error was gone.

    After digging through the functions.php of my (child) theme I found the function and action which caused the error.

    add_action('admin_init', 'my_function_name');

    I hope this helps others!

  • Geef een reactie