Title: Warning: array_key_exists()
Last modified: August 10, 2021

---

# Warning: array_key_exists()

 *  Resolved [cuckoofairweb](https://wordpress.org/support/users/cuckoofairweb/)
 * (@cuckoofairweb)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/warning-array_key_exists-21/)
 * Hi, this is probably similar to other error report. On the above page I am getting
   this error:
    Warning: array_key_exists() expects parameter 2 to be array, unknown
   given in /homepages/2/d451850435/htdocs/app451850410/wp-content/plugins/media-
   library-assistant/includes/class-mla-shortcode-support.php on line 798
 * It’s repeated 6 times and appears before the first line of text.
 * The HTML of the page is this:
 *     ```
       <a id="topofpage"></a>Here's the 'phrases' that have been used to 'tag' each photo in the gallery. The larger the text the more photos there are of that phrase. Click a phrase to see its photos displayed below.
   
       [mla_tag_cloud taxonomy="attachment_category,attachment_tag" number=0 post_mime_type=image/jpeg exclude="70,97,73,74,151,74,75,96,110,162,172,173,175" separator=" | " mla_link_href="{+page_url+}?current_id={+term_id+}&current_name={+name,url+}"]
   
       [mla_gallery post_mime_type="a-bad-type" mla_nolink_text="{+template:(
       <h3>Here's the photos for {+request:current_name+}</h3>
       Click a photo to enlarge it in the slideshow display, once there click the photo to display the next one. Click on the background page to return here.)+}"][/mla_gallery]
   
       [mla_gallery]
       post_mime_type=image/jpeg
       tax_query="array (
       'relation' => 'OR',
       array ( 'taxonomy' => 'attachment_category',
       'field' => 'id',
       'terms' => array( {+request:current_id+} ),
       'include_children' => false,
       ),
       array ( 'taxonomy' => 'attachment_tag',
       'field' => 'id',
       'terms' => array( {+request:current_id+} ),
       ),
       )"
       orderby=date
       order=ASC
       size=icon
       link=file
       mla_alt_shortcode=justified_image_grid
       [/mla_gallery]
       ```
   
 * I am running WordPress 5.8 running Responsive Mobile theme
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fwarning-array_key_exists-21%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/warning-array_key_exists-21/#post-14755548)
 * Thanks for your report. I regret the trouble you’re having with the latest MLA
   version. The PHP Warning message is a result of an MLA change I made in v2.96.
 * I have released MLA version 2.97, which corrects the problem and has a few other
   improvements as well. I am marking this topic resolved, but please update it 
   if you have any trouble with the latest version.
 *  Thread Starter [cuckoofairweb](https://wordpress.org/support/users/cuckoofairweb/)
 * (@cuckoofairweb)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/warning-array_key_exists-21/#post-14758424)
 * Hi David,
 * As ever thanks for the prompt response and for adding in the description field
   too – a nice bonus.
 * A quick once over on the web site has highlighted that the above page and code
   now:
    * displays all images on initial load but without the opening header that
   gets displayed if you click a term in the tag cloud * The display of all images
   includes one (the penultimate one – Zac and the Zeroes that has no valid Att 
   Categories or Att Tags!)
 * Thanks
 * Paul
 *  Thread Starter [cuckoofairweb](https://wordpress.org/support/users/cuckoofairweb/)
 * (@cuckoofairweb)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/warning-array_key_exists-21/#post-14777909)
 * Hi David I’m not sure if you’ve seen my updated description of what now happens
   after the initial fix.
 * The page now displays all images when it is first opened but without this header
   text (the choice was for ‘the Plonkers’):
    “Here’s the photos for The Plonkers
   Click a photo to enlarge it in the slideshow display, once there click the photo
   to display the next one. Click on the background page to return here.” This header
   text is displayed properly when the any category link is displayed.
 * Also, on the initial opening of the page all images are displayed including those
   without any of the selected categories – I exclude several that aren’t relevant
   for the tag cloud.
 * Thanks
 * Paul
 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/warning-array_key_exists-21/#post-14786212)
 * I regret that I did not understand your first update. Thanks for trying again.
 * The missing “header text” is a result of your content template. You have parentheses
   around the entire text, which means the text is suppressed when there is no value
   for the `{+request:current_name+}` substitution parameter. You can try this alternative:
 *     ```
       mla_nolink_text="{+template:(<h3>Here's the photos for {+request:current_name+}</h3>)
       Click a photo to enlarge it in the slideshow display, once there click the photo to display the next one. Click on the background page to return here.+}"
       ```
   
 * Note that I have moved the closing parenthesis to the end of the header tag, 
   so the “click a photo…” always appears. You could also try something like:
 *     ```
       mla_nolink_text="{+template:<h3>Here's the photos for {+template:{+request:current_name+}|all tags+}</h3>
       Click a photo to enlarge it in the slideshow display, once there click the photo to display the next one. Click on the background page to return here.+}"
       ```
   
 * That should display “all tags” or the selected tag.
 * The “all images are displayed” issue is happening because your `[mla_gallery]``
   tax_query` does not have any exclusion clause for the terms excluded from the
   cloud. I will have to do some experimenting to give you the syntax of an exact
   solution. I will post an update when I have progress to report.
 *  Thread Starter [cuckoofairweb](https://wordpress.org/support/users/cuckoofairweb/)
 * (@cuckoofairweb)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/warning-array_key_exists-21/#post-14787800)
 * David,
 * I’m very sorry but having written a poor post I have now confused you as well!
 * The way the page used to work was that:
    On initial load it’d just display the
   tag cloud, no images would be displayed. Hence the opening text “Here’s the ‘
   phrases’ that have been used to ‘tag’ each photo in the gallery. The larger the
   text the more photos there are of that phrase. Click a phrase to see its photos
   displayed below.” You’d click a term from the tag cloud and the text “Here’s 
   the photos for <<Clicked Term>> Click a photo to enlarge it in the slideshow 
   display, once there click the photo to display the next one. Click on the background
   page to return here.” followed by all photos with that term.
 * The main issue at the moment is that somehow it displays all images as part of
   the initial load – ie before a term is clicked. I suspect if that is fixed then
   the other issue that of displaying images without the required tags will be fixed…
 * Sorry for the confusion.
 * Paul
    -  This reply was modified 4 years, 9 months ago by [cuckoofairweb](https://wordpress.org/support/users/cuckoofairweb/).
 *  Thread Starter [cuckoofairweb](https://wordpress.org/support/users/cuckoofairweb/)
 * (@cuckoofairweb)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/warning-array_key_exists-21/#post-14787865)
 * Hi I have updated the page to add some ‘debug’ code. It looks like this shortcode:
 *     ```
       [mla_gallery]
       post_mime_type=image/jpeg
       tax_query="array (
       'relation' => 'OR',
       array ( 'taxonomy' => 'attachment_category',
       'field' => 'id',
       'terms' => array( {+request:current_id+} ),
       'include_children' => false,
       ),
       array ( 'taxonomy' => 'attachment_tag',
       'field' => 'id',
       'terms' => array( {+request:current_id+} ),
       ),
       )"
       orderby=date
       order=ASC
       size=icon
       link=file
       mla_alt_shortcode=justified_image_grid
       [/mla_gallery]
       ```
   
 * Is being run as part of the initial load…
 *  Thread Starter [cuckoofairweb](https://wordpress.org/support/users/cuckoofairweb/)
 * (@cuckoofairweb)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/warning-array_key_exists-21/#post-14788176)
 * David,
 * Hi a further update. Using WordPress’s version history I have restored the version
   that was created seven months ago and has worked as expected since then.
 * That’s the version that’s currently running and it displays the same symptoms
   eg displays images on initial load with no tag cloud term having been clicked.
 * Paul
 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/warning-array_key_exists-21/#post-14789647)
 * Thanks for your updates and clarifications. I now understand (I hope) that the
   only problem you have with the current display is that on page load, all images
   are displayed and what you want is no images displayed; is that right?
 * To display no images on the initial page load requires a simple change to your
   second `[mla_gallery]` shortcode. Try something like this:
 *     ```
       [mla_gallery]
       post_mime_type=image/jpeg
       tax_query="array (
       'relation' => 'OR',
       array ( 'taxonomy' => 'attachment_category',
       'field' => 'id',
       'terms' => array( {+template:{+request:current_id+}|1+} ),
       'include_children' => false,
       ),
       array ( 'taxonomy' => 'attachment_tag',
       'field' => 'id',
       'terms' => array( {+template:{+request:current_id+}|1+} ),
       ),
       )"
       orderby=date
       order=ASC
       size=icon
       link=file
       mla_alt_shortcode=justified_image_grid
       [/mla_gallery]
       ```
   
 * The changes are to both of the `'terms' =>` tax_query parameters. I have added
   a template that supplies a default term ID (‘1’) when the `{+request:current_id
   +}` value is empty. The default won’t match any items and the display will be
   empty.
 * You wrote “**_I have restored the version that was created seven months ago_**“.
   Did you change the WordPress version or the MLA version or the page content? 
   I don’t know why the display would have changed.
 * I hope the above suggestion gives you the results you desire.
 *  Thread Starter [cuckoofairweb](https://wordpress.org/support/users/cuckoofairweb/)
 * (@cuckoofairweb)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/warning-array_key_exists-21/#post-14790716)
 * Hi David,
 * Many thanks the |1+ did the trick!
 * Tapping into some of my previous software development techniques I restored back
   to the last known good working copy which was the January one when you originally
   helped me setup the tag cloud. The only changes since then have been to the WordPress
   version, possibly PHP and the updates to your amazing MLA.
 * I have no idea why it suddenly stopped working ok? Maybe there was a re-coding
   deep in the bowels of WordPress core that changed the way in which the terms 
   expression was parsed? If it’d help I’m happy to turn on MLA debugging?
 * Regards
 * Paul
 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/warning-array_key_exists-21/#post-14792025)
 * Thanks for confirming that the suggestion was helpful.
 * I don’t know when or why the terms expression parsing changed, but it was an 
   accident that it worked in the past; no further debugging required. The template
   approach is the right solution.
 * I am marking this topic resolved because the original issue has been addressed.
   If you have any problems or further questions regarding the other query-related
   material, start a new topic for them. Thanks for your continued interest in the
   plugin.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Warning: array_key_exists()’ is closed to new replies.

 * ![](https://ps.w.org/media-library-assistant/assets/icon-256x256.png?rev=973502)
 * [Media Library Assistant](https://wordpress.org/plugins/media-library-assistant/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/media-library-assistant/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/media-library-assistant/)
 * [Active Topics](https://wordpress.org/support/plugin/media-library-assistant/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/media-library-assistant/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/media-library-assistant/reviews/)

 * 10 replies
 * 2 participants
 * Last reply from: [David Lingren](https://wordpress.org/support/users/dglingren/)
 * Last activity: [4 years, 9 months ago](https://wordpress.org/support/topic/warning-array_key_exists-21/#post-14792025)
 * Status: resolved