get_category_link()
accept the category ID or object and you are passing the post ID.the_category()
acceptSeparator
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
}
Related Posts:
- How to exclude categories from recent posts, recent comments & category widgets?
- How to Link to Most Recent Custom Post of Same Term
- Homepage custom recent news
- Linking to the most recent post in my podcast category
- How to check if I’m on the last page of posts?
- Multisite – Protect categories from deletion?
- Where/how are categories stored?
- Get top parent category
- wp_update_nav_menu_item() to insert categories
- Redirecting specific category posts to subdomain
- How can I prevent users from creating new categories?
- Get child categories when clicking on parent category
- Block multiple categories from Blog
- Best and Cleanest way to remove /category/ from category permalinks? [duplicate]
- Categories list loop – add separator every year
- What type of page should i use? static page or category page? and what’s the difference? [closed]
- Categories vs. Page Site Organization
- Get last post date yesterday from each categories not work & double result post
- How do I add a function on a specific post category?
- Open subcategories in submenu on click in primary menu
- How to add Categories to the top menu of the website?
- Multiple categories PROBLEM and Duplicating main categories
- force category base – archive pages work WITH & WITHOUT category base slug in url?
- Retrieve Image from Media Library by it’s category
- Getting URL of archive (category) page
- Strip a word from wp_list_categories
- Get Unique Categories – Group By?
- Site search needs to find posts for category topic AND Tag or keyword thats not in the post
- Get category url in loop
- Previous/next post links displaying wrong category than is desired
- SQL to migrate post types to taxonomy
- category url structure
- Order by category titles
- How to conditionally hide author name on Single.php if category is “news”, otherwise if category is something else display author name?
- How to let users choose posts order in categories?
- WordPress category
- Different Output for “Every Other” Foreach Statement?
- And/Or Category Query
- Automatically redirect a page to a category that share the same slug
- Show subcategories on a parent category page
- How do I add Category Body Classes to Admin?
- not all categories being displayed
- Category archive is displaying all posts rather than the specific category
- Use the category name instead of category slug in permalinks
- How can I display the number of post associated to a category in Twig/Timber WordPress? [closed]
- How to display the parent category if only the child category has been chosen
- Multiple Category Search with and operator in WordPress
- get_posts() from parent category only using a shortcode
- Display list categories from CTP
- Different CSS class by category
- Remove any product that is featured from regular display loop [WooCommerce]
- Edit tag_id in category pages of dashboard
- Deleting a category from WordPress admin does it remove it completely from the database?
- WP_Query – using category__and when one of the categories is 0
- Multiple categories for one menu item?
- Hide categories from frontend, but not admin / post editor
- Exclude categories from homepage not longer working
- Post to inherit custom category background image from parent
- Related posts widget – category
- Editing Loop So It Targets Specific Tags?
- Last x Posted Categories?
- Check boxes for showing categories
- Header Link function not working. Problem with bloginfo()
- WordPress category filters as subcategories
- Sort posts alphabetically by category/custom taxonomy, insert divider between different types
- Need help with major category and permalink re-organization
- Is there a “sensible” limit to WordPress Categories?
- Possible to make get_categories() hide_empty attribute honor excludes from post query?
- Display Category Name and Date Posted on Blog Post
- Modifying category order
- How to remove “Categories:” part after the post title? [closed]
- Please tell how to stop the category from showing up on posts
- how to get only grandchild category from a child category
- Editing categories crashes WordPress site
- Remove “category” from permalink with add_rewrite_rule
- Next and previous links category infinite loop
- Conditional Site Logo(Category Based)
- show only terms from parent category
- Tag Menu items based on their categories
- Accessible Subcategory URL’s pages without using .php hack
- How to display total views of all posts of one category?
- in_category(‘category-sluga’) returns true for Archive page of Category ‘category-slugb’
- wp_list_category only showing to logged in uers
- Grouping parent categories into sections
- How to show “category” name?
- Display the category name of a post that is in two different categories
- Querying Multiple Categories With Different Offsets
- filter single_cat_title avoiding the breadcrumbs
- htaccess redirect for all categories converted to tags now showing 404
- altering theme – content generated by PAGES not PORTFOLIO
- Category page with gallery for each post
- (WordPress) How to get custom taxonomy parent name?
- How do i add custom post types to this query?
- add new input field like category?
- WordPress excerpt for specific posts in category
- How do I get a single page navigation depending on the previous page?
- Search functionality with multiple categories
- Make a menu visible for a single category and it’s content
- How to define category ID in an array?
- Restricted category in Woocommerce [closed]