Title: Upgrade Error:  in_array() expects parameter 2 to be array
Last modified: August 20, 2016

---

# Upgrade Error: in_array() expects parameter 2 to be array

 *  Resolved [noxbane](https://wordpress.org/support/users/noxbane/)
 * (@noxbane)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/upgrade-error-in_array-expects-parameter-2-to-be-array/)
 * I’ve been using this code in some widgets for about a year now with no issues:
 * `if ( !in_array(39,get_post_ancestors($post)) && !in_array(42,get_post_ancestors(
   $post)) ) return true;`
 * And also this one:
 * `global $post; return (in_array(39,get_post_ancestors($post)));`
 * All it does is display the widget if WordPress is displaying a particular post
   or one of its children.
 * But now I’m suddenly seeing a whole bunch of these errors at the top of every
   page:
 * Warning: in_array() expects parameter 2 to be array, boolean given in /home/besthome/
   public_html/wp-content/plugins/widget-logic/widget_logic.php(284) : eval()’d 
   code on line 1
 * [http://wordpress.org/extend/plugins/widget-logic/](http://wordpress.org/extend/plugins/widget-logic/)

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

 *  [alanft](https://wordpress.org/support/users/alanft/)
 * (@alanft)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/upgrade-error-in_array-expects-parameter-2-to-be-array/#post-3298824)
 * not sure why this would have changed in WP3.5. But the first bit of get_post_ancestors
   has this
 * `if ( ! $post ) return false;`
 * so something you could try is adding an initial test of $post in the condition
   like
 * `return ($post) && (in_array(39,get_post_ancestors($post)));`
 * so that if $post is false it doesn’t go on to test it against the function. just
   a first thought – not really thought it out.
 *  Thread Starter [noxbane](https://wordpress.org/support/users/noxbane/)
 * (@noxbane)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/upgrade-error-in_array-expects-parameter-2-to-be-array/#post-3298839)
 * Hi Alan,
 * Thank you very much for going above and beyond and researching this for us. I
   wish all plugin authors were so willing to help.
 * Your fix worked great for my second example. However it doesn’t for the first.
 * Specifically, changing this:
 * `if ( !in_array(39,get_post_ancestors($post)) && !in_array(42,get_post_ancestors(
   $post)) ) return true;`
 * to this:
 * `if ( ($post) && !in_array(39,get_post_ancestors($post)) && !in_array(42,get_post_ancestors(
   $post)) ) return true;`
 * will get rid of the error, but now that particular widget will never show at 
   all.
 * Do you have any idea why this would be?
 *  [alanft](https://wordpress.org/support/users/alanft/)
 * (@alanft)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/upgrade-error-in_array-expects-parameter-2-to-be-array/#post-3298840)
 * do you have the “global $post” at the start?
 *  Thread Starter [noxbane](https://wordpress.org/support/users/noxbane/)
 * (@noxbane)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/upgrade-error-in_array-expects-parameter-2-to-be-array/#post-3298841)
 * No I didnt, but I added it and it now works:
 * `global $post; if ( ($post) && !in_array(39,get_post_ancestors($post)) && !in_array(
   42,get_post_ancestors($post)) ) return true;`
 * Oddly enough, I never had it before and it worked fine before the 3.5 upgrade.
   Ah well, I’m just glad it works now. Many thanks.
 *  [cbush57](https://wordpress.org/support/users/cbush57/)
 * (@cbush57)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/upgrade-error-in_array-expects-parameter-2-to-be-array/#post-3298873)
 * This really helped me today too! Just all of a sudden one of my client’s sites
   broke with this error. I just had to check for the array first:
 * $whichPage = get_field(‘which_page?’);
    if( ($whichPage) && in_array(….
 * Thanks everyone!!

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

The topic ‘Upgrade Error: in_array() expects parameter 2 to be array’ is closed 
to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/widget-logic_c8dde5.svg)
 * [Widget Logic](https://wordpress.org/plugins/widget-logic/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/widget-logic/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/widget-logic/)
 * [Active Topics](https://wordpress.org/support/plugin/widget-logic/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/widget-logic/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/widget-logic/reviews/)

 * 5 replies
 * 3 participants
 * Last reply from: [cbush57](https://wordpress.org/support/users/cbush57/)
 * Last activity: [12 years, 8 months ago](https://wordpress.org/support/topic/upgrade-error-in_array-expects-parameter-2-to-be-array/#post-3298873)
 * Status: resolved