Added check to make sure that post->ID is set in subpages function