ACF fields not showing on a wordpress custom taxonomy page

淺唱寂寞╮ 提交于 2019-12-23 03:11:53

问题


I'm having trouble showing ACF on a custom taxonomy page.

The custom tax is 'destinations' with the page being taxomony-destinations.php the field is called 'destination_landing_image. I'm trying to display it on 'mysite.com/destinations/coutryname' as follows:

<?php if (have_posts()) : while (have_posts()) : the_post();
$destination_landing_image = get_field('destination_landing_image');
<img src="<?php echo $destination_landing_image['url'] ?>" alt="<?php echo    $destination_landing_image['alt'] ?>">
<?php endwhile; endif; ?>

Oddly enough the page in question does show up the ACF fields within the custom post type(holidays) which is lower in the page. So I guess firstly am I calling it correctly within the loop? and Secondly is a custom taxonomy the right type of page to use?


回答1:


When you use ACF with posts you can just use get_field() as you are, but when you use it with anything else such as taxonomies, users or options, you need to give ACF a hint about how to look it up. In this case you need to tell it what taxonomy and term you are specifically targeting. Luckily both WordPress and ACF make this really easy:

//Ask WordPress for the currently queried object
//http://codex.wordpress.org/Function_Reference/get_queried_object
$obj = get_queried_object();

//Pass that object as a second parameter into get_field
$destination_landing_image = get_field( 'destination_landing_image', $obj );


来源:https://stackoverflow.com/questions/25548276/acf-fields-not-showing-on-a-wordpress-custom-taxonomy-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!