I have a small problem with showing all post categories for each post inside my loop on custom archive page.
This is How I try to show them:
$categories = get_the_terms( $post->ID, 'section' );
foreach ((array) $categories as $category) {
echo '<span class="kat-label">'. $category->name . '</span>';
}
As you can see there is a custom taxanomy "section" and I have there also custom post type called "games".
The problem is output. Some posts display correct cattegory names, some of them display none, and others show the same category name for example 7 times!
I was trying to debug WP and I got something like that for results where 0 categories shows:
Warning: Attempt to read property "name" on bool in /home/....
And for others
Trying to access array offset on value of type null in /home/....../archive-games.php on line 238
The same code works perfect on single post whre categories are shown correctly.
Any ideas how to fix that?
3
Answers
OK. So there was a BUG in WPML (I have checked the WPML changelog) multilangual plugin. Updating WPML fixed the problem.
I think this solution Is what you looking for.
Copid from answer
Edit: – Improved
It seems you are missing ID of the post or you are not mentioning correct taxonomy.
Try adding :