简体   繁体   English

ACF字段未显示在wordpress自定义分类页面上

[英]ACF fields not showing on a wordpress custom taxonomy page

I'm having trouble showing ACF on a custom taxonomy page. 我在自定义分类页面上显示ACF时遇到问题。

The custom tax is 'destinations' with the page being taxomony-destinations.php the field is called 'destination_landing_image. 定制税为“目的地”,页面为taxomony-destinations.php,该字段称为“ destination_landing_image”。 I'm trying to display it on 'mysite.com/destinations/coutryname' as follows: 我正尝试将其显示在“ mysite.com/destinations/coutryname”上,如下所示:

<?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. 奇怪的是,相关页面确实在页面下方的自定义帖子类型(假日)内显示了ACF字段。 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? 其次,自定义分类法是要使用的正确页面类型吗?

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. 当对帖子使用ACF时,可以按get_field()使用get_field() ,但是当将其与其他类(如分类法,用户或选项)一起使用时,则需要给ACF有关如何查找它的提示。 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: 幸运的是,WordPress和ACF都使这变得非常容易:

//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 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM