Title: User Meta error when meta doesn&#8217;t exist
Last modified: February 17, 2023

---

# User Meta error when meta doesn’t exist

 *  Resolved [jleenman](https://wordpress.org/support/users/jleenman/)
 * (@jleenman)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/user-meta-error-when-meta-doesnt-exist/)
 * Please help. I can’t find a solution for this case.
 * An item needs to be displayed based on a **user meta value**. This works fine:
   if the value is in the array the content shows, if the value is not in the array
   it doesn’t. But some users may not have the meta value set (array doesn’t exist),
   other users are just visitors and not logged in.
 * Both cases throw the error:
 * ![](https://i0.wp.com/uc33cdc48f9df0bf8c2a05bb5157.previews.dropboxusercontent.
   com/p/thumb/AB0GuueJC7C2wqNooi9RC6JIaVFec6_obGrU0JSOeGKmbpgO3kzef0p3VawUZzyROgAFpMfUgJRvlV04w5ieaNrCwMEcSg9fEoqS5qS50VacV3pN5EE14IYzSkZI-
   GOHRpQL1a4ZidCC1K_e5BZZy1dU3_Y5hWLaDfjII8RXjWVqWG6L-hS0czm5ONf7BKVQxq8WUAJ9BuqzRZee604hrEz3YmDoIh6A0Ye7VjhNYGGJ0ZiYa3oo_jVRjNMIyUgXAlRmRjFP4m6OPWkE7d9pkBt2VDku5Pgw_jL-
   gmvSo-qJwju0WQPP5MX_sb7Dwufk5iMb8SK_c3Q_jrOWjuZBLhO6Bgghh5QSuNapN6K2fpuwOOaSMVZNVant9zct9ZfGmSmmMfwbmrGlHLnHzzKpFxp81zSfaZ07trcqVJX5s9hpVA/
   p.png?ssl=1)
 * `Fatal error: Uncaught TypeError: array_intersect(): Argument #1 must be of type
   array, bool given...`
 * I understand what causes the error, but can’t figure out how to solve it. Adding
   a user role condition with ‘condition type = all’ does not solve this problem.

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

 *  [john](https://wordpress.org/support/users/johnweru/)
 * (@johnweru)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/user-meta-error-when-meta-doesnt-exist/#post-16486154)
 * Hi there,
 * Thanks for reaching out to us.
 * With respect to your query here, kindly share with us the actual context of this
   error based on your site. Also please share with us replication steps to this
   error.
 * I look forward to your reply.
 * Kind Regards,
 * John
 *  Thread Starter [jleenman](https://wordpress.org/support/users/jleenman/)
 * (@jleenman)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/user-meta-error-when-meta-doesnt-exist/#post-16487798)
 * Hi John,
 * The complete actual context of my site is quite complicated and not very useful
   to share here.
   To reproduce you need at least [Elementor](https://wordpress.org/plugins/elementor/)
   and [Visibility Logic](https://wordpress.org/plugins/visibility-logic-elementor/).
 * You can use [Code Snippets](https://wordpress.org/plugins/code-snippets/) to 
   import this snippet: [dropbox link](https://www.dropbox.com/s/51dr2uaylgxnunt/add-user-meta-options-page.code-snippets.json?dl=0).
   
   Import the snippet in Code snippets and activate. It adds a very basic option
   page in the WordPress admin (Settings->Save User Meta) with a button to add example
   user meta for all users.
 * Click the button ‘Update User Meta’ to add the user meta key.
 * _(optionally you could use [JSM’s Show User Metadata](https://wordpress.org/plugins/jsm-show-user-meta/)
   to verify that the key has been added to all user profiles, see image below. 
   This plugin also makes it easy to remove the meta key: red icon)_
 * ![](https://i0.wp.com/uc641e377917098d6d472873cb07.previews.dropboxusercontent.
   com/p/thumb/AB0LJXf9ZTaUlCoDKj5oP7AnCcS8efxfxbhhSQlUzlrEiRNusdhUs1mNul-cEhql5x4FsF04UVlciR8nOzAJlu_i3AxN9jmyCjHEAg2sG0H96UePFViXZexxsdwEah5sfDyasvfP9ExFf4aew4FcZjQQNGFFtiyziFEpRTCWzX6Jq2dUavORROorjU-
   HVryXjS3q40yNAMVBjayXWcuosWJgQniX2ihD5GjaIyXXOM1996pRCLKeTxmW2chYeeUfj--EsI1y7aVOoNno3Mbul0reJ-
   FDuCOss_VPbcrREFMnoA65YCvzyVYSXpNM_bls-sO_O1y37ZfzAZ-VPEPL8IqCsRRWaYH0cRjAlXCekj6DDp79yW34SGvT5yzGVSHnSe8t1ngjHeu07ubpsLSEYQH0UhhsACx_EYL8-
   4RdbSXMcA/p.png?ssl=1)
 * Then create a page in Elementor, add any element and add these Visibility logic
   settings:
 * ![](https://i0.wp.com/uc8242496a5d43409f12e29c9299.previews.dropboxusercontent.
   com/p/thumb/AB0Hc_A4uks-LpU5EHnMZEXRYnMnL0EWqbVVqDYKcPk_PBu2MMACTV2JcHo60LSePsszJOFj8xyNKcU37_tfWqzQy7i7dx7Dt2hRbpW5jw7c15keB8TKzCmq1p8_SLvZrqwFP9Qs9488xDNlQ3XrTQnuwzzu58i5p2-
   oteradxQ1bXRP7vIOZKgcD2SGruMlOuw550Gk2i1MQ5CZPW3SQeYx3VGjusF2xKzqXbRVV_RC6xDZDIXiO4ROizFUYWM5EbfY5hI0Zweqe4vTEMLAo0SDgOYnm9MRExJUHnJ36y3lq2whyOORLQN_sF6Kj4mfNJbZv-
   wQT68WVNEB4RcLI_LT7RiL2iquRtw-EfBK0W_b27pzB-q5KhJV25XzrbEvzABGs1zsRBXRu72_ZIhVMRyewEc8WnnwJFOtV7ak7eHDQA/
   p.png?resize=266%2C152&ssl=1)
 * ![](https://i0.wp.com/ucac33be141d1b677771551f81e1.previews.dropboxusercontent.
   com/p/thumb/AB1TLEYndsXV74EhU51ukP5IJjM-ZN5DeDWS7sd3DrJwGvyD_v2NTN2cftR-c5dMx8Glgr5fmbSOMsmo632sjBg5sv055F3PY6kPaLAzO3jxNyzwCIfzzoDVkn07Tox1tf-
   zxKfCzKmoq3XHQLPXBctQknqiDqR39y2ZMdzsdhpfFawZ8DWCxrCUd_5IOi_fIsATSazYCNmUj4TojanzMXho0EECnEfiUFCYOPW3uqsZtRquvU0-
   XgaMhoIKnesudseR8jqFiJ4DxKDa2GH5xXqZOKD4LJjdjz5xQrC04-0owRvb5SCukYBwMHcTfiHDO60Vcg_l6LNilj8ZjJomEhBH2FpMmOESLgH9lq9GJJzqs_dqBxozxiqOnJDIpxOQUaIeKKiIh27oEMI213L8EluH1XAiV-
   zqTFsF1LgAE3ph1A/p.png?resize=266%2C357&ssl=1)
 * Verify that these settings work as intended by visiting the page as a logged-
   in user. The element should show. If you change ‘value_1’ to anything that’s 
   not in the meta key (e.g. ‘value_4’) the element does not show.
 * **Now for the error:** visit the same page in incognito mode (or logged-out) 
   to reproduce. 
   The same error happens if you now remove the meta key with [JSM’s Show User Metadata](https://wordpress.org/plugins/jsm-show-user-meta/)
   or for any new user before you add the key with my snippet. It happens every 
   time that the user meta key doesn’t exist, which from a technical viewpoint is
   to be expected.
 * But with Visibility Logic I can’t figure out how to add a check to first verify
   if the user is logged-in, or to check if the key exists.
 * **Conclusion:** I need a way to use the User meta option of Visibility Logic,**
   _without_** breaking that page for logged-out users. In that case the condition
   result should be equal to ‘false’ (element not visible).
 *  Thread Starter [jleenman](https://wordpress.org/support/users/jleenman/)
 * (@jleenman)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/user-meta-error-when-meta-doesnt-exist/#post-16487816)
 * Maybe this can be a feature request: an extra option in the User Meta section
   of Visibility Logic that determines how to handle a non-existing meta key.
 *     ```wp-block-code
       Option: 
       When the user meta does not exist (e.g. for guest visitors) the result of the condition is FALSE:
       -> Toggle (ON/off)
       ```
   
 * I need a solution sooner though (unless you can release such a feature fast 🙂
 *  [john](https://wordpress.org/support/users/johnweru/)
 * (@johnweru)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/user-meta-error-when-meta-doesnt-exist/#post-16495850)
 * Hi there,
 * Thanks for keeping in touch with us.
 * In this case, the screenshots you embedded cannot be previewed. I did however
   try out the steps to replicate the issue and did surely come across a fatal error.
   I will notify the lead team about this so that this is fixed. In the meantime,
   please navigate to the visibility-logic-elementor\core\settings\UserMetaVisibility.
   php and on line 327, alter the code in place to:
   `if ( !is_user_logged_in() |
   | empty( array_intersect( $user_meta, $values ) ) ) {`
 * I hope this helps.
 * Kind Regards,
 * John
 *  Thread Starter [jleenman](https://wordpress.org/support/users/jleenman/)
 * (@jleenman)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/user-meta-error-when-meta-doesnt-exist/#post-16509449)
 * Thank you!
 * This has solved the issue for users that are not logged in.
 * The same error still happens when a user is logged in but the meta key doesn’t
   exist for that user. In my case I can write my code so that this shouldn’t happen,
   but maybe the team should consider adding a check for that case too.
 * I think that Visibility Logic should handle that case as if the array would exist
   but the value is not in it.
 * Thanks again for the help!
    -  This reply was modified 3 years, 2 months ago by [jleenman](https://wordpress.org/support/users/jleenman/).
      Reason: marked as solved
 *  [john](https://wordpress.org/support/users/johnweru/)
 * (@johnweru)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/user-meta-error-when-meta-doesnt-exist/#post-16514337)
 * Hi there,
 * Thanks for sharing this information.
 * In this case, I have notified the lead team about this matter so that it is looked
   into detail.
 * Apologies for the inconvenience that this has caused.
 * Kind Regards,
 * John

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

The topic ‘User Meta error when meta doesn’t exist’ is closed to new replies.

 * ![](https://ps.w.org/visibility-logic-elementor/assets/icon-256x256.png?rev=2534122)
 * [Visibility Logic for Elementor](https://wordpress.org/plugins/visibility-logic-elementor/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/visibility-logic-elementor/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/visibility-logic-elementor/)
 * [Active Topics](https://wordpress.org/support/plugin/visibility-logic-elementor/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/visibility-logic-elementor/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/visibility-logic-elementor/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [john](https://wordpress.org/support/users/johnweru/)
 * Last activity: [3 years, 2 months ago](https://wordpress.org/support/topic/user-meta-error-when-meta-doesnt-exist/#post-16514337)
 * Status: resolved