$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Wordpress the_category(); only works with message-posts not with project posts, how do I specify project categories?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin10PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far