My custom query not detecting the correct category

in your code, you are checking the category of a post which is quite random outside of the loop and when the posts have more than one category;

the category ID of a category archive page is usually:

$cat_ID = get_query_var('cat');

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)