Use the function get_the_category();
inside the WordPress loop and pass the get_the_ID()
function which will get the current post ID in the loop.
get_the_ID()
will return the post id and whereas the the_id();
will just display.
if( $the_query->have_posts() ) : while( $the_query->have_posts() ) : $the_query->the_post();
$category_array = get_the_category( get_the_ID() );
print_r( $category_array );
endwhile;
endif;
wp_reset_postdata();
Hopefully, the above code will solve the issue.
Related Posts:
- How to show related posts by category or custom post type?
- How to create posts (not post template) to be displayed on projects page?
- Query Custom Post by Category
- Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?
- Loop on front-page.php
- Show custom post type filtered by category
- WP Query with categories only shows one post and ignores the category
- WP the_posts() on single-cars.php get category link
- Custom post types and ‘new WP_Query’
- WP_Query with custom post type ID
- display posts of custom post type with custom taxonomy
- Display post from custom post type
- Use post in multiple places on a page with multiple posts
- How to fetch posts that are stored in the different table than (default) wp_posts?
- SEARCH QUERIES – REVERSE OUTPUT
- subtracting the current post form then whole loop, which is generating all CPT titles
- Custom Post By Category
- Custom post Query and WordPress Post Query Clash
- How To Loop Through list with Custom Post Types
- Custom Post Type + Category archive
- How do you get the count of posts in an archive page?
- how do I group content in magazine-style ‘issues’?
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- New WP_query in template not working with CPT+category on some pages
- WP Query group/order by category name
- Should unaltered default loop/query return a list of custom posts belonging to a custom taxonomy?
- exclude custom post type by meta key in wp_query
- Query for posts in 2 taxonomies
- Loop through categories and create tab for each
- How do I create an archive page for standard posts?
- Display types of posts in edit.php instead of All, Published, Scheduled and Draft
- Unable to get post content from custom post type loop
- Custom Taxonomy – Tags Metabox is showing instead of Categories
- Remove duplicated values from a loop
- WordPress Orderby Numeric Value Not Working
- Custom Post Type Loop within Shortcode
- is there a way to retrieve posts that do not have a featured image assigned?
- How to connect two custom post types with nested loops
- How to show CPTs in term archive
- How to add post_type=value when editing that post type in the WordPress admin?
- Display CPT posts based on specific taxonomy
- Show one item per category of a custom post type
- Storing posts from query and accessing later via AJAX call
- Showing posts from different categories and from custom post type
- Show a Category X’s custom post type on Category X archive page?
- Custom Post Slug same as Parents Category Slug
- Problem: wp_query outputs all images on site
- Prioritize posts in query by meta keys?
- How to get all tags of a custom post type by id
- Custom Post Type Category Link
- Custom Post type category pages template and loop
- Conditional for a Single Post That Belongs to a Category?
- Create new custom post and post category of same name
- Using wp_query to modify the loop in index.php for a CPT
- Custom WP_Query doesn’t display all posts
- Query & the_content() is showing in the header
- Variable not working in WP_Query
- Pagination not working on custom query on a page
- Query within a foreach within a query (queryception)
- wordpress lists similar type of posts in a custom post type
- WP Query results showing posts outside of category ID
- Restrict category access to specific users/groups. Author always has access
- How to get Custom Post Type with Categories wise in WordPress using wp_query
- Posts are not rendering perfectly [closed]
- get_terms() parent, child and grandchild
- list posts of two post types in a single template
- WP_Query of Category Not Showing First Post
- How to properly use Categories with Custom Post Types
- How do I list a custom field and custom taxonomies for each result in a loop?
- Custom Post Type Query W/Category Dropdown
- Multiple custom post type queries causing wrong post types to be grabbed in taxonomy + single templates?
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- Show the categories the current post has
- Page that lists publications by classifying them by taxonomy
- Exclude a specific post in a Custom Post Type
- Pin posts to top of custom loop
- Filtering posts based on three taxonomies
- wp_post_delete is deleting all offices
- Custom WordPress theme not displaying posts from category
- How to show posts of the same category on a page?
- Error in the page of a CPT file in WordPress
- post type => ‘any’ not applied my custom queries
- Display title of all custom posts from same taxonomy term on a custom post template
- Query the title of the page to show posts with matching category in the loop
- Most efficient way of showing children posts?
- WordPress query in which condition uses custom field
- Custom post types not displaying per category
- Error in WP Query. If variable is empty it is displaying previous post value
- Is it possible to add query parameters on the archive page?
- Query Posts From Multiple Post Types
- Make assigning post to a specific category equivalent to assigning it to all categories
- next_posts_link returns same content of 1st page
- Custom loop won’t work, can’t find problem
- Categories and page filtering with pre_get_posts
- Get all custom_post_type posts + blog posts from one category in a single query
- How to exclude certain portfolios from a loop
- How do I hide single category post on my post page
- show the most recent date of all posts to display on front end
- Can WordPress show posts based on a button that the user clicked 2 pages back?
- Sort ACF by custom taxonomy