Wordpress the_category(); only works with message-posts not with project posts, how do I specify project categories?

admin2025-06-03  4

The title, the permalinks & even the field of ACF do work smoothly. But the code is not reactive to project categories, when I echo wp_list_categories(); it shows the list of message posts only. How do I specify that it should echo project categories instead? Current code:

$args = array( 'post_type' => 'project', 'posts_per_page' => 10);
$loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post();

echo '<ul>';
echo '<li>';the_title(); echo '</li>';
echo '<li>';wp_list_categories(); echo '</li>';
echo '<li>';the_category(); echo '</li>';
echo '<li>';the_field(Prijs); echo '</li>';
echo '</ul>';

endwhile;

The title, the permalinks & even the field of ACF do work smoothly. But the code is not reactive to project categories, when I echo wp_list_categories(); it shows the list of message posts only. How do I specify that it should echo project categories instead? Current code:

$args = array( 'post_type' => 'project', 'posts_per_page' => 10);
$loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post();

echo '<ul>';
echo '<li>';the_title(); echo '</li>';
echo '<li>';wp_list_categories(); echo '</li>';
echo '<li>';the_category(); echo '</li>';
echo '<li>';the_field(Prijs); echo '</li>';
echo '</ul>';

endwhile;
Share Improve this question edited Jan 29, 2019 at 14:35 Chinmoy Kumar Paul 9436 silver badges7 bronze badges asked Jan 29, 2019 at 14:27 L.eroyL.eroy 32 bronze badges 3
  • Are you registered any taxonomy for "project" post type? – Chinmoy Kumar Paul Commented Jan 29, 2019 at 14:37
  • Nope, I just realized projects is a custom post type from Divi. I'm gonna look into taxonomy now! – L.eroy Commented Jan 29, 2019 at 14:39
  • 1 hopefully get_the_term_list will help you. See the codex for more details codex.wordpress/Function_Reference/get_the_term_list – Chinmoy Kumar Paul Commented Jan 29, 2019 at 14:41
Add a comment  | 

1 Answer 1

Reset to default 0

the_category and wp_list_categories are for the category taxonomy term. What most people call a category is most likely a taxonomy. Category is just a default taxonomy for the post post type.

You need to use the general taxonomy functions such as the_terms and get_the_term_list.

echo '<li>'; echo get_the_term_list($post->ID, 'project_category'); echo '</li>';

You will need to change project_category to whatever custom taxonomy name you have used.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748964831a315213.html

最新回复(0)