admin管理员组文章数量:1434916
Would love some help on a website I'm currently building because I seem to not get something to work. The website has a custom post type 'evenement'. I have created a custom taxonomy 'locatie' and last but not least I have made a Field group item 'evenement_locatie', linked to the custom taxonomy.
I made a template for that show's a single evenement post, that show's the custom fields which I get with this code
<p><?php the_field("event_startdate"); ?><br> om <?php the_field("event_starttime"); ?></p>
This works fine for all fields, however I can't seem to load the custom taxomony, and I tried all codes that I could find online. This is the code I'm currently using:
<?php $term = get_field('evenement_locatie');
if( $term ): ?>
<h2><?php echo esc_html( $term->name ); ?>test</h2>
<p><?php echo esc_html( $term->description ); ?></p>
<?php endif; ?>
And I have also tried
<?php echo get_field('evenement_locatie', get_queried_object()); ?>
Also tried to use the get_term function, but I can't figure out how to get it working. I also trying using get_field('locatie') and that does not work as well.
My goal is to show the taxonomy title, and the description, but I've tried for hours now to get something. Also the WP_DEBUG is not giving me any error's as well, so don't know how to continue.
Any tips or tricks? Thanks in advance!
Would love some help on a website I'm currently building because I seem to not get something to work. The website has a custom post type 'evenement'. I have created a custom taxonomy 'locatie' and last but not least I have made a Field group item 'evenement_locatie', linked to the custom taxonomy.
I made a template for that show's a single evenement post, that show's the custom fields which I get with this code
<p><?php the_field("event_startdate"); ?><br> om <?php the_field("event_starttime"); ?></p>
This works fine for all fields, however I can't seem to load the custom taxomony, and I tried all codes that I could find online. This is the code I'm currently using:
<?php $term = get_field('evenement_locatie');
if( $term ): ?>
<h2><?php echo esc_html( $term->name ); ?>test</h2>
<p><?php echo esc_html( $term->description ); ?></p>
<?php endif; ?>
And I have also tried
<?php echo get_field('evenement_locatie', get_queried_object()); ?>
Also tried to use the get_term function, but I can't figure out how to get it working. I also trying using get_field('locatie') and that does not work as well.
My goal is to show the taxonomy title, and the description, but I've tried for hours now to get something. Also the WP_DEBUG is not giving me any error's as well, so don't know how to continue.
Any tips or tricks? Thanks in advance!
Share Improve this question asked Nov 17, 2024 at 16:25 Casper BoonCasper Boon 5711 bronze badges1 Answer
Reset to default 0I think the issue is when creating a taxonomy field in ACF, the default result value will be a term ID, not a term object. Your code is correct but it's only work with the term object only.
You can check the return value in ACF setting like this screenshot
There are 2 options here
- Update the return value in ACF to Term Object so you can use the current code.
- Use the new code below to get the field you need
<?php
$term_id = get_field('evenement_locatie');
if($term_id):
$term = get_term($term_id);
?>
<h2><?php echo esc_html($term->name); ?>test</h2>
<p><?php echo esc_html($term->description); ?></p>
<?php endif; ?>
本文标签: phpShow custom taxomony on custom single post typeStack Overflow
版权声明:本文标题:php - Show custom taxomony on custom single post type - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745631900a2667325.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论