The following snippet will let you solve multiple loops problem in WordPress.