Notice: Undefined variable: category_id

Seems to me that you want to get the ID of your current category. You need to first get the category using :

Method 1

$myCategory = get_the_category();

And then instead of $category_id` use this:

$myCategory[0]->cat_ID;

To retrieve the ID. OR:

Method 2

$myCategory = get_queried_object(); to get the category and replace $category_id with:

$myCategory->term_id;