Looping the data from WordPress database using foreach

I finally figure it out, I didn’t call the method on instance correctly, inside the if statement if ($val->idworkType == $post['worktype']). I used this $post['worktype'] instead of this $post->worktype.

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