wp_get_post_categories()
and get_category()
are specifically for the category
taxonomy. You’re using a custom taxonomy, portfolio_cat
, so you need to use get_the_terms()
to get categories.
$categories = get_the_terms( $post_id, 'portfolio_cat' );
$cat_str="";
foreach ( $post_categories as $category ) {
$cat_str .= $category->name;
}
If you just want a comma separated list of category links, you can use get_the_term_list()
to simplify the code:
$cat_str = get_the_term_list( $post_id, 'portfolio_cat', '', ', ', '' );
Or, if you don’t want links, you can do this instead:
$categories = get_the_terms( $post_id, 'portfolio_cat' );
$cat_str = implode( ', ', wp_list_pluck( $categories, 'name' ) );
Also, instead of $query->post->post_title
you should really just be using get_the_title();
.
Related Posts:
- How can i list custom post type categories?
- Add category attribute to custom shortcode
- Get Posts by Category, Tag , and CPT Taxonomy
- How to seperate posts by categories?
- How to call Shortcode categories for custom post types?
- Using get_terms() as shortcode attribute
- How to separate posts by categories?
- Exclude a category from WP_Query
- Custom Post Types on Category Pages
- Adding Categories to a WordPress Custom Post Type?
- How to display regular posts & custom post types that fall under a category using just the generic category template?
- Display custom post type with shortcode
- How to filter custom post types by custom category taxonomy
- How to list all categories and tags in a page?
- Pagination not working with custom category template
- remove support for ‘Categories’ for a custom post type
- Remove date and category filters when editing custom post types
- Anyway to assign custom post types to a specific category?
- List with categories, subcategories and posts of custom posttype
- wp_list_categories and custom post types
- Automatic category for a Custom Post Type
- Query Custom Post by Category
- How to display the categories of the post? (custom post type)
- Post the content of a specific “Custom Post Type” post within a post using a shortcode
- Display Custom Category (taxonomy) Name in Custom Post Type
- CPT posts listed by category with custom rewrite URL, please help!
- Multiple custom post type loops in category.php
- Add category in post type dynamically
- Shortcode insertion in tab
- How to get the post type from a category id?
- Insert HTML inside link in a walker
- Use regular category with custom post types
- Set menu active state for custom posttype and category, given custom taxonomy term
- Getting posts under the custom post type ui category
- Separate custom categories from default category
- How to display custom taxonomies with links in filter menu?
- Cannot add category or custom taxonomy from admin. WordPress site is hosted in Windows 16 server via IIS. No XAMPP or WAMP
- Add custom post type settings to wordress default posts
- Hide parent categories when clicked, and show it’s childs
- Custom post type, organized by categories
- How to render a custom post type template with custom fields using shortcode
- Remove CPT name from permalink but add %category% instead
- Set a checkmark in a category based on a URL-parameter
- Multiple (two) category postings on the same page.
- School & class blogs: Categorize with categories or custom posts?
- How to get custom posts sub category link
- Categories filtering in new post
- CPT category hierarchy
- How can I have different content for different countries?
- Invalid Taxonomy
- Displaying Custom Posts
- How to include category name/id in wp_query for retrieving “custom post type” from a particular category?
- Custom shortcode works in Elementor editor but not on frontend
- Custom post type Shortcodes wordpress
- Include custom post type custom taxonomies in Categories widget
- Add shortcode inside of the_content()
- custom query with custom post type and category slug
- WordPress custom post categories and subcategories on category.php
- Custom Post Type for Shortcode Use – Prevent it display as a post (with slug)
- Use post in multiple places on a page with multiple posts
- Custom Post Type Custom Archive Page Not Working
- Can’t pull posts of a Custom Post Type based on the custom taxonomy of the CPT
- Archive Template being used instead of Category Template for Custom Post Type
- Custom post type specific category box
- Custom Taxonomy Taxonomies of Same Name point to first created URL
- category.php not showing custom post types
- Show in an entry a Custom Post Type associated to a post
- Post category behave like a Post in back office menu
- Save data is post using php front end
- Modify category permalink to use post type slug
- How to output custom post type title on custom page with category next to it?
- Create custom post type categories
- From CPT Custom Loop into Shortcode?
- Custom post type shortcode with taxonomy attribute not working and no errors
- Set a Default CPT taxonomy by taxonomy id
- Load custom post type with ID in a shortcode
- Automatic Set Category For A Custom Post Type
- how to create custom taxonomy drop downs for parents and child
- Only show categories that have posts within custom post type
- How to create groups like that in buddypress?
- How to Show all Values in category.php page using post_type
- Getting list of Categories for Custom Post Types
- can’t see categories in appearance-menu-categories
- Custom Post Type + Category archive
- Exclude categories For Custom post types
- Show custom post type in archive page by category
- I have a custom post type that I want to query a dynamic category name from a custom meta field
- Display all post types together
- Trying to create hierarchy between 3-4 custom post types
- Having some trouble properly displaying Custom Post Types in templates
- Displaying wp post categories into my custom metabox
- adding a shortcode into a custom post type
- Nested loop called with shortcode duplicating the content above the main loop
- Add number in increment of one to DIV ID
- WordPress custom post type post and category links 404
- show only one category posts in admin
- One set of categories for multiple custom posts
- Choose custom post type template by category
- Are custom posts included when getting a categories’ posts?
- Categorizing Custom Posts in Bulk Based on Title