Title: Warning message &quot;Warning: in_array() expects parameter 2 to be array, null given
Last modified: August 20, 2016

---

# Warning message "Warning: in_array() expects parameter 2 to be array, null given

 *  [AdreaUI](https://wordpress.org/support/users/adreaui/)
 * (@adreaui)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/warning-message-warning-in_array-expects-parameter-2-to-be-array-null-given/)
 * The site I am working on has many pages with many menus. I currently have the
   parent pages and their ancestors showing the pertinent menu according to code
   in the sidebar.php and the following function:
 *     ```
       // Check if page is an ancestor
       function is_ancestor($post_id) {
           global $wp_query;
           $ancestors = $wp_query->post->ancestors;
           if ( in_array($post_id, $ancestors) ) {
               return true;
           } else {
               return false;
           }
       }
       ```
   
 * My news page (where posts are displayed) is a child of About. When I try to call
   the About Menu as per the rest of the site I get the following warning:
 * Warning: in_array() expects parameter 2 to be array, null given in /Users/…./
   functions.php on line 138
 * I am working locally so unfortunately I cannot provide a link to the site.

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

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/warning-message-warning-in_array-expects-parameter-2-to-be-array-null-given/#post-3078408)
 * Check that `$ancestors` is an array before trying to use it:
 *     ```
       if ( is_array($ancestors) && in_array($post_id, $ancestors) ) {
       ```
   
 *  Thread Starter [AdreaUI](https://wordpress.org/support/users/adreaui/)
 * (@adreaui)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/warning-message-warning-in_array-expects-parameter-2-to-be-array-null-given/#post-3078459)
 * Sorry for my ignorance. I am learning pHp as I go.
 * Where should I put this statement? In functions.php or within the sidebar.php
   where I am trying to call the menu? How would I specifically check the news page?
   The above function works perfectly for the rest of the site. It is only the posts
   page (news) that I get the warning on.
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [13 years, 8 months ago](https://wordpress.org/support/topic/warning-message-warning-in_array-expects-parameter-2-to-be-array-null-given/#post-3078461)
 * You prepend your current `if` condition to consider checking for an array,
    E.
   g your code should be
 *     ```
       // Check if page is an ancestor
       function is_ancestor($post_id) {
           global $wp_query;
           $ancestors = $wp_query->post->ancestors;
           if ( is_array($ancestors) && in_array($post_id, $ancestors) ) {
               return true;
           } else {
               return false;
           }
       }
       ```
   
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/warning-message-warning-in_array-expects-parameter-2-to-be-array-null-given/#post-3078467)
 * Yes, what I gave you was a rewrite of one of the lines of code that you provided.
 *  Thread Starter [AdreaUI](https://wordpress.org/support/users/adreaui/)
 * (@adreaui)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/warning-message-warning-in_array-expects-parameter-2-to-be-array-null-given/#post-3078474)
 * Okay gotcha. I amended the code and the warning disappeared. Great!
 * Now knowing this what would be the recommended way to call the About Menu? This
   page is still, for all intents and purposes, a child page of About. I still need
   to call the About Menu but have to do it differently than the current mechanism
   used for all other pages.
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/warning-message-warning-in_array-expects-parameter-2-to-be-array-null-given/#post-3078476)
 * How did you make your blog index a ‘child’ of your about page?
 *  Thread Starter [AdreaUI](https://wordpress.org/support/users/adreaui/)
 * (@adreaui)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/warning-message-warning-in_array-expects-parameter-2-to-be-array-null-given/#post-3078477)
 * I say it’s a child page because it is not a link on the main nav but rather you
   have to first go to About. Then there is a sub-nav with a News link.
 * I have the respective menus showing on the rest of the site by using the following
   code:
 *     ```
       <?php
       if ( is_page( 'solutions' )) {
       	wp_nav_menu(array('menu'=>'solutions-menu' ));
       }
       elseif ( is_page( 'webcasts' ) || is_ancestor( '17' ) ) {
       	wp_nav_menu(array('menu'=>'webcasts-menu' ));
       }
        ?>
       ```
   
 * This doesn’t seem to be working with the posts page. I also tried naming it directly
   e.g.
 *     ```
       <?php
       if ( is_page( 'solutions' )) {
       	wp_nav_menu(array('menu'=>'solutions-menu' ));
       }
       elseif ( is_page( 'news' )) {
       	wp_nav_menu(array('menu'=>'about-menu' ));
       }
        ?>
       ```
   
 * This also doesn’t seem to work. I am getting a menu but not the correct one. 
   Instead I am getting a menu consisting of News and Press Releases. Press Releases
   is the other post page I have on this site. I use categories to post each to 
   it’s own page.
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/warning-message-warning-in_array-expects-parameter-2-to-be-array-null-given/#post-3078478)
 * Ok. You are talking about how you have your links setup, about how your front
   end user interface is constructed. I need to know how the pages and posts are
   setup in the backend. I need to know how it looks to the software and how it 
   looks to the server, not how you lead users to it.

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

The topic ‘Warning message "Warning: in_array() expects parameter 2 to be array,
null given’ is closed to new replies.

## Tags

 * [Ancestor](https://wordpress.org/support/topic-tag/ancestor/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [warning](https://wordpress.org/support/topic-tag/warning/)

 * 8 replies
 * 3 participants
 * Last reply from: [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * Last activity: [13 years, 8 months ago](https://wordpress.org/support/topic/warning-message-warning-in_array-expects-parameter-2-to-be-array-null-given/#post-3078478)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
