Afișarea numelui categoriei pentru un tip de postare personalizat
Am o interogare personalizată în care afișez rezultatele postărilor dintr-un tip de postare personalizat numit "staff". Acest tip de postare personalizat este legat de o taxonomie personalizată numită "department". Pot afișa rezultatele, dar nu reușesc să afișez categoria care este asociată fiecărei postări.
Acesta este codul meu:
<?php
$args = array(
'post_type' => 'staff', 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'departments',
'field' => 'slug',
'terms' => 'board'
)
)
);
$loop = new WP_Query( $args );
?>
<?php if( $loop->have_posts() ): ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<p class="text-center name"><?php the_title(); ?></p>
<?php the_category(' '); ?>
<?php endwhile; ?>
<?php endif; ?>
Cred că problema este că folosesc the_category dar nu sunt sigur.
Aveți idei ce ar putea fi greșit?
Mulțumesc!

folosește termeni astfel:
$terms = get_the_terms($post->ID, 'Introdu_taxonomia_aici');
if ($terms && ! is_wp_error($terms)) :
$tslugs_arr = array();
foreach ($terms as $term) {
$tslugs_arr[] = $term->slug;
}
$terms_slug_str = join(" ", $tslugs_arr);
endif;
echo $terms_slug_str;

În cazul în care cineva caută acest lucru în 2019. Cu acest cod obții numele TIPULUI DE POSTARE PERSONALIZATĂ (CUSTOM POST TYPE) împreună cu URL-ul său.
$terms = wp_get_post_terms( $post->ID, 'PUNE-AICI-TAXONOMIA-TA');
foreach ( $terms as $term ) {
$term_link = get_term_link( $term );
echo '<a href="' . $term_link . '">' . $term->name . '</a>' . ' ';
}

$categories = get_terms(array( 'taxonomy' => 'course_categories', 'hide_empty' => false, ));
$output .= '<select name="category">';
$output .= '<option value="">Selectează Categoria</option>';
foreach ($categories as $category) {
$output .= '<option value="' . $category->slug . '">' . $category->name . '</option>';
}
if (!empty($category_data)) { // Dacă o categorie este selectată, filtrează după acea categorie $post['tax_query'] = array( array( 'taxonomy' => 'course_categories', 'field' => 'slug', 'terms' => $category_data, 'operator' => 'IN', ), ); }
