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
- get_template_part for custom post type content not working
- Custom Taxonomy – Tags Metabox is showing instead of Categories
- wp_query to find posts by year and month
- WP_Query is printing out only one post when posts_per_page is set to multiple
- How to get all posts except for one post from a certain custom post type?
- Remove duplicated values from a loop
- Querying Term Posts in 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?
- WP_Query | ‘post_type’ doesn’t work
- How to connect two custom post types with nested loops
- How to get the post type from a category id?
- Filter by custom taxonomy slug on a custom post type
- Pagination on category page with custom post types
- Query custom post type in the loop
- Loop through Custom Post Type, and then show children within each iteration
- Very Slow Page – How to Optimize # of Queries?
- Can I create a loop with multiple post types and specify different $args for each post type?
- 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
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- showing custom post types of a certain category only
- WP_Query orderby modified to include custom meta changes
- Linking to the most recent post in a Custom Post Type
- Getting posts under the custom post type ui category
- How to make sure content doesn’t display if selection is empty
- Show one item per category of a custom post type
- Storing posts from query and accessing later via AJAX call
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- Custom loop with multiple taxonomy queries
- I would like to have different styles for my posts based on the content of each post
- forming WP_Query for posts of all post types but from specific categories
- Showing posts from different categories and from custom post type
- Get latest 3 posts from multiple CPT in one query
- List custom taxonomy specific to one custom post type
- Show a Category X’s custom post type on Category X archive page?
- Add custom post type settings to wordress default posts
- Problem with displaying posts in the CPT category
- Custom post type, organized by categories
- What’s the WP way to load remaining custom posts?
- Set a checkmark in a category based on a URL-parameter
- Several post types on WP Query by tag and taxonomy
- Get the category from custom post type
- Custom Post Slug same as Parents Category Slug
- Shortcode not working with post counter
- Problem: wp_query outputs all images on site
- Why is my category template ignoring post type?
- Prioritize posts in query by meta keys?
- How to get all tags of a custom post type by id
- How can I show 1 featured post in a styled element, and the next few below differently styled
- pagination not working for category.php (custom post types in categories)
- Custom Post Type Category Link
- Custom Post type category pages template and loop
- Redirect to another page using contact form 7? [closed]
- Conditional for a Single Post That Belongs to a Category?
- Wrapping x posts in html without leaving empty html
- WP Query post__in not returning correct results
- Sort posts in loop by the WooCommerce Membership of the author
- Different Limit number of post on different archive page
- Create new custom post and post category of same name
- Tag page only display 10 posts
- How can I group posts by months and years?
- Multiple Custom Post Type queries, how to DRY it up
- Custon Content within WordPress Loop
- Loop increase number
- Using wp_query to modify the loop in index.php for a CPT
- WP_Query Custom Post Type if Category ID Equals
- Custom WP_Query doesn’t display all posts
- Query & the_content() is showing in the header
- Variable not working in WP_Query
- How to Display Posts From Category Within a Custom Taxonomy?
- Showing custom post type categories in the menu
- get_pagination not working on a custom post type query (using WP_Query)
- How to Make infinite loop of post
- How to include category name/id in wp_query for retrieving “custom post type” from a particular category?
- Stores category posts in an array
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- Pagination not working on custom query on a page