• Resolved nathan12343

    (@nathan12343)


    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)
  • 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

    (@nathan12343)

    Perfect!

    The first one didn;t work. Just came back with a blank page, but the second did the trick exactly!!!

    Many thanks

    oops… well I did misspell ‘ancestors’ in the first one…

    Thread Starter nathan12343

    (@nathan12343)

    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.