Please try below updated code
<?php
$recent_posts = wp_get_recent_posts(array(
'post_status' => 'publish',
'cat' => '',
));
foreach($recent_posts as $post) : ?>
<div class="card">
<div class="card-bg">
<div class="card-cat">
<?php
$category_detail=get_the_category($post['ID']);//Pass POST ID
foreach($category_detail as $cd){
echo $cd->cat_name.'';
}
?>
</div>
<img class="card-img" src="https://wordpress.stackexchange.com/questions/337072/<?php echo get_the_post_thumbnail_url( $post["ID'] ); ?>">
</div>
<div class="card-body">
<div class="card-title">
<?php echo $post['post_title'] ?>
</div>
</div>
</div>
<?php endforeach;
wp_reset_query(); ?>
Try and let me know if any query.
Hope it will help!
Related Posts:
- What does the token %1$s in WordPress represent [closed]
- exclude multiple terms using get_terms() function
- Getting key value of WP_Term object in wordpress
- Archive listing of posts by publish year (multiple years)
- Add custom field to attachments in a specific category
- Display all posts in current category
- Looking to exclude blog posts from category Previous/Next buttons
- How to display related posts from parent category
- How can I set custom order use this function
- Put a link to a category round a hard coded A HREF
- Check if Product is in a Specific Category in Functions.php
- How to exclude specific category from the get_the_category(); array
- Add HTML Attributes To Anchor Tags In `wp_list_categories()` Function
- Category Thumbnail Display – How to display ONLY the main Category
- Where do posts get the sidebar from?
- combine Code 1 with Code 2
- get post based on category chosen in drop down – The ajax method
- Creating a related post section based on similar categories
- Swapping wp_dropdown_categories function with wp_category_checklist
- Issue adding sub category programmatically
- Grab posts by multiple categories
- get_template_part based upon post’s category
- how to save selected option in variable for rest api category filter
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Different post styles depending on category
- Display category name only once inside loop
- how to show only specific category for a template
- Creating sub-categories via php
- Define specific category name in PHP
- Edit the_category (); for a hierarchical display
- Category title output before opening title tag
- Include Parent Term in wp_list_categories
- How to array only one key from another array
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- Displaying posts based on category
- How do I remove a category from a wordpress loop>
- Get categories names as an array to use it in theme settings
- How to get the last category name of a child category?
- How to hide posts of a specific custom category in WordPress?
- Post not populating for custom post type based on category selection
- Add new post in existing categories using wp_insert_post
- How to change logo by category
- Problem with custom loop and wp_list_pluck [closed]
- Listing titles and custom fields of entries within subcategories
- random display categories – change url
- Output category list inside array
- Do not duplicate posts with multiple categories in multiple loops
- Removing sidebar on category pages
- WooCommerce: Display product categories to make IF statement
- Trying To Get Child Categories To Show, Issue With foreach Loop
- Define category ID using get_post_meta
- How To Pass Array To get_the_category_by_ID() and Get An Array Back?
- go to home page when i select default in select-box
- Adding wp_list_categories to a specific div that was appended using jQuery
- Counting number of posts in multiple (sub)categories using shortcode
- Wrong Number of Products When Hiding Subcategory Products From Showing In Parent Category
- I need to display posts in subcategory beside posts in main category
- Add Custom Category Description When Empty
- Order category posts by last word of custom field
- Add a product category to a specific product via a button
- Change category thumbnail size
- Get nice name of category from slug (remove dashes of category)
- Display Visual Composer shortcode if a post belongs in specific categories
- admin panel – How to remove “delete” button from category editing page
- Get parent category name when only child category is applied to a product
- Multiple Tag Filtering
- How to Link to category titles if it is in the single post content?
- Polylang and template files
- How can i show specific Category List?
- Notice: Undefined variable
- How to show category just on specific pages?
- Show subcategory name selected in specific category woocoommerce
- How to filter specific element of an array in wordpress/php?
- Admin backend, show post from a category and exclude the posts from subcategories
- Custom content using in_category
- PHP drop down menu for my get_category child of
- Short code into PHP
- PHP get_category() function redeclared
- List categories assigned to a post
- Unable to get Post Category Name and URL
- Need to adjust condition to say if I’m pulling categories from a post, to pull only the first one
- Rearrange get_categories array compared to another array
- Search in particular category in wordpress
- Query seems to be duplicated
- Top menu disapears in Category Pages when filtering using ACF
- Trying to see if page is category or single and displaying title with appropriate heading tag
- Error trying import one category on page
- !in_array doesnt recognize category
- How to change links in the 3 main categories, on widget category, to a javascript function call
- Remove the_content From Loop
- Category List in Theme Options Page
- how to set category name for a post
- Code that displays images – images get shown multiple times
- category & sub category order issues in wordpress
- Display post of specific category on page
- Displaying categories
- Fix incorrect related posts code snippet
- Display a list of posts corresponding to a category
- How to create categories out of a list of words?
- Is there a way of displaying related posts from lowest hyrachical order (lowest child category to parent category)