Support

Account

Home Forums Front-end Issues Uncaught TypeError: Cannot read property 'query' of undefined

Solved

Uncaught TypeError: Cannot read property 'query' of undefined

  • Hi @steviec

    Great to hear that you solved it and thank you for posting your solution here for others to find 🙂

  • Yes what StevieC said. Users need to have a minimum of an Author role in order to upload media files otherwise you get that non-descriptive error,

  • Might be interesting to know that it’s to upload files without permissions if you do it through acf_form() in the front end. However then it will always use the regular upload input type rather than WordPress native.

    Just some info for people that might find this topic.

  • I think it actually defaults to the basic uploader if you don’t have permissions. However, the gallery field is the control that does not work.

  • @tabboy
    Yeah that’s what I meant by:

    However then it will always use the regular upload input type rather than WordPress native.

    The gallery field needs WordPress core functionality to work so yeah that’d probably be a different case 🙂

  • This error occurs in Chrome Browser when you read a property or call a method on an undefined object . Uncaught TypeError: Cannot read property of undefined error is probably easiest to understand from the perspective of undefined, since undefined is not considered an object type at all (but its own undefined type instead), and properties can only belong to objects within JavaScript. There are a few variations of this error depending on the property you are trying to access. Sometimes instead of undefined it will say null.

  • Hello all,

    I am also getting the same error as @tabboy but on line 10260 in acf-input.js. I have an Image field inside of a repeater and when I click on ‘Add Image’, I receive an “Uncaught TypeError: Cannot read ‘query’ of undefined” for the following:

    var Query = wp.media.query( options.library );

    I am using WordPress 5.2.4 and ACF Pro Version 5.8.6.

    I would also like to mention that this is happening on a Charitable campaigns post in the backend. Here is a reference to that plugin: https://www.wpcharitable.com/extensions/charitable-ambassadors/

    To test whether it has something to do with the repeater, I created a new field group with just an Image field to show on my campaign post but that also didn’t work so the repeater is not at fault. For some reason, the media modal is not opening up as it should.

    I have tried this on both Chrome and Firefox with no luck.

    Any help is much appreciated! Thank you!

  • Hi,
    I have read all the post. Have the same problem, but inside the editor of pages (where my admin upload posts.. not public)

    The error raises upon pressing the “upload image” button. No dialog appears.

    Console error is:

    acf-input.min.js?ver=5.8.7:3 Uncaught TypeError: Cannot read property 'query' of undefined
        at n.addFrameStates (acf-input.min.js?ver=5.8.7:3)
        at n.initialize (acf-input.min.js?ver=5.8.7:3)
        at n.e (acf-input.min.js?ver=5.8.7:1)
        at n.acf.Model (acf-input.min.js?ver=5.8.7:1)
        at n [as constructor] (acf-input.min.js?ver=5.8.7:1)
        at new n (acf-input.min.js?ver=5.8.7:1)
        at Object.acf.newMediaPopup (acf-input.min.js?ver=5.8.7:3)
        at n.selectAttachment (acf-input.min.js?ver=5.8.7:2)
        at n.onClickAdd (acf-input.min.js?ver=5.8.7:2)
        at n.<anonymous> (acf-input.min.js?ver=5.8.7:1)

    Wordpress ver 5.3.1

    All plugins updated

    any ideas? I’m driving mad.

    Thanks!

  • Hi,

    My error was happening on a custom post type created by a plugin called Charitable that allows for ACF fields on the page. I reached out to them about the JavaScript errors since they weren’t occurring on any other of my custom post types. They responded saying that it’s an issue related to a bug that happens with their Recurring Donations extension when it is not installed alongside their plugin.

    So the solution for me was to install the extension and luckily that fixed everything.

    Are you editing WordPress pages or pages from a plugin? If it is from a plugin, I would try contacting them.

    Best of luck!

  • Hi all.
    I know this is an old thread now, but what did the trick for me (on WP 5.5.3 and ACF PRO 5.9.3) is just adding this to the template I’m working on:

    wp_enqueue_media();

  • I did this and now I have a form for uploading an image but then when I try to upload an image I get this error

    sorry you are not allowed to upload files.

  • Hello, I receive exactly the same error: I am using the gallery field in a front end form. When clicking on “Add to Gallery” nothing happens, the Chrome console throws the following error message (see below). Adding the line “wp_enqueue_media();” in the page template before the ACF form leads to the exact error (displayed in the front end media upload form) mentioned by Karush, i.e. “Sorry you are not allowed to upload files”.
    What else can I do? I am using the latest ACF Pro 5.11.4 version.
    Thanks!
    Ralph

    “acf-input.min.js?ver=5.11.4:1 Uncaught TypeError: Cannot read properties of undefined (reading ‘query’)
    at n.addFrameStates (acf-input.min.js?ver=5.11.4:1)
    at n.initialize (acf-input.min.js?ver=5.11.4:1)
    at n.e (acf.min.js?ver=5.11.4:1)
    at n.acf.Model (acf.min.js?ver=5.11.4:1)
    at n [as constructor] (acf.min.js?ver=5.11.4:1)
    at new n (acf.min.js?ver=5.11.4:1)
    at Object.acf.newMediaPopup (acf-input.min.js?ver=5.11.4:1)
    at n.onClickAdd (acf-pro-input.min.js?ver=5.11.4:1)
    at n.<anonymous> (acf.min.js?ver=5.11.4:1)
    at HTMLAnchorElement.i (jquery.min.js?ver=3.6.0:2)”

  • My issue was related to incorrect registering of the fields through PHP. I needed the field to show in two locations and issue was related to incorrect array nesting of the ‘location’ property. Here’s the working example.

    acf_add_local_field_group([
            'key'                   => 'G1570820135490',
            'title'                 => 'Extras',
            'fields'                => $fields,
            'location'              => [
    			[
    				[
    					'param'    => 'nav_menu_item',
    					'operator' => '==',
    					'value'    => wp_get_nav_menu_object('mega')->term_id,
    				]
    			],
    			[
    				[
    					'param'    => 'nav_menu_item',
    					'operator' => '==',
    					'value'    => wp_get_nav_menu_object('mega-australia')->term_id,
    				],
    			],
            ],
            'menu_order'            => 0,
            'position'              => 'normal',
            'style'                 => 'seamless',
            'label_placement'       => 'top',
            'instruction_placement' => 'label',
            'active'                => true,
    ]);
Viewing 13 posts - 26 through 38 (of 38 total)

The topic ‘Uncaught TypeError: Cannot read property 'query' of undefined’ is closed to new replies.