Title: 404 &amp; wrong datatype for array
Last modified: August 19, 2016

---

# 404 & wrong datatype for array

 *  Resolved [nathan12343](https://wordpress.org/support/users/nathan12343/)
 * (@nathan12343)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/404-amp-wrong-datatype-for-array/)
 * I’ve got a function that finds out if the current page is a sub page of another.
   Lifted the code from a post here I think:
 *     ```
       <?php // detect the page tree and set the stylesheet accordingly
       function is_tree($p_id) {
       	global $post;
       	if(is_page()&&(in_array($p_id, $post->ancestors) ||
       	   $post->post_parent==$p_id ||
       	   is_page($p_id)))
       	return true;
       	else return false;
       };
       ?>
       ```
   
 * This lets me add a style sheet according the the top level parent. Anyway. When
   testing the 404 page the header goes wrong:
 * > Warning: in_array() [function.in-array]: Wrong datatype for second argument
   > in /home/fhlinux133/i/inq-chat.duttonsdev.co.uk/user/htdocs/inq_cms/wp-content/
   > themes/chat_combined/desk_header.php on line 39
 *  with line 39 being the 3rd line of code above.
 * This error is repeated 8 times.
 * Any ideas?

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

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/404-amp-wrong-datatype-for-array/#post-1289592)
 * That’s probably your call to ‘in_array’. That’s the only function with two arguments,
   and the error fits. ‘in_array’ needs `$post->ancestors` to be an array. If `$
   post->ancestors` isn’t set or isn’t an array you’ll get that error. So you want
   to make sure that ‘is_array’ doesn’t run unless `$post->ancestors` is an array.
   Something like:
 *     ```
       if(is_page()&&(is_array($post->acncestors) && in_array($p_id, $post->ancestors) ||
       ```
   
 * Casting might work too.
 *     ```
       if(is_page()&&(in_array($p_id, (array)$post->ancestors) ||
       ```
   
 *  Thread Starter [nathan12343](https://wordpress.org/support/users/nathan12343/)
 * (@nathan12343)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/404-amp-wrong-datatype-for-array/#post-1289691)
 * Perfect!
 * The first one didn;t work. Just came back with a blank page, but the second did
   the trick exactly!!!
 * Many thanks
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/404-amp-wrong-datatype-for-array/#post-1289693)
 * oops… well I did misspell ‘ancestors’ in the first one…
 *  Thread Starter [nathan12343](https://wordpress.org/support/users/nathan12343/)
 * (@nathan12343)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/404-amp-wrong-datatype-for-array/#post-1289756)
 * didn’t like to mention it after the help 😉

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

The topic ‘404 & wrong datatype for array’ is closed to new replies.

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [nathan12343](https://wordpress.org/support/users/nathan12343/)
 * Last activity: [16 years, 6 months ago](https://wordpress.org/support/topic/404-amp-wrong-datatype-for-array/#post-1289756)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
