Get The Post Category If You Have A Custom Post

[Solved] Get The Post Category If You Have A Custom Post | Php - Code Explorer | yomemimo.com
Question : Displaying the category name of a custom post type

Answered by : isaac-groisman-afzx9092x66j

<?php $terms = wp_get_post_terms( $post->ID, 'PLACE-HERE-YOUR-TAXONOMY'); foreach ( $terms as $term ) { $term_link = get_term_link( $term ); echo '<a href="' . $term_link . '">' . $term->name . '</a>' . ' '; } ?>

Source : https://wordpress.stackexchange.com/questions/189055/displaying-the-category-name-of-a-custom-post-type | Last Update : Tue, 28 Dec 21

Question : Get the post category if you have a custom post_type

Answered by : indonesia-people

<?php
/* FIRST
 * Note: This function only returns results from the default “category” taxonomy. For custom taxonomies use get_the_terms().
 */
$categories = get_the_terms( $post->ID, 'taxonomy' );
// now you can view your category in array:
// using var_dump( $categories );
// or you can take all with foreach:
foreach( $categories as $category ) {
    echo $category->term_id . ', ' . $category->slug . ', ' . $category->name . '<br />';
}

Source : https://developer.wordpress.org/reference/functions/get_the_category/ | Last Update : Wed, 11 May 22

Answers related to get the post category if you have a custom post type

Code Explorer Popular Question For Php