Show posts by category – category ID not working

Of course it doesn’t work. What examples are using this code?

Let’s take a look at Category Parameters of WP_Query

There are 5 category parameters:

  • cat (int) – use category id.
  • category_name (string) – use category slug.
  • category__and (array) – use category id.
  • category__in (array) – use category id.
  • category__not_in (array) – use category id.

There is no category parameter on that list, so your parameter is unknown and WP_Query ignores it.

So how should it look?

...
$args = array(
    'cat' => 172,
    'post_type' => 'post',
    'posts_per_page' => 10,
    'paged' => $paged
);
...

PS. Also… You shouldn’t use the_title() in HTML attributes – it won’t get escaped properly. So if the title contains quote character, then it will break your HTML code…

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