I recently encountered this problem when I changed my permalink settings (away from the default /?=123 method into something more custom, i.e. /%category%/%postname%) and added rewriting rules into my lighttpd system.
Anyhow, this is to let y’all know that the
if ( !$posts )
to if ( !$posts || !$posts[0]->ID )
patch works for me ??