List recent posts with link to first category

  • get_category_link() accept the category ID or object and you are passing the post ID.
  • the_category() accept Separator as a first parameter to separate multiple categories and again you are passing post ID.
  • You can use get_the_category to get all the categories and then display one of category information.

Example:-

$all_post_categories = get_the_category($recent["ID"]);
$category_obj = isset($all_post_categories[0]) && is_object($all_post_categories[0]) ? $all_post_categories[0] : false;
if ($category_obj) { ?>
    <a class="previous-post-cat" href="https://wordpress.stackexchange.com/questions/220470/<?php echo get_category_link($category_obj); ?>"><?php
        echo $category_obj->name; ?>
    </a><?php
}

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