Error: Attempt to read property “ID” on null

Where did you put that function ? that’s better call that it inside the action, the error probably coming from missing variable.

add_action('init','newFunction');
function newFunction(){
 global $wp_query;
 // Do your code here
}

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