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

2024-02-09

我在自定义分类页面上显示 ACF 时遇到问题。

自定义税是“目的地”,页面为taxomony-destinations.php,该字段称为“destination_landing_image”。我试图将其显示在“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; ?>

奇怪的是,相关页面确实显示了页面下方的自定义帖子类型(假期)中的 ACF 字段。所以我想首先我在循环中正确调用它吗?其次,自定义分类法是正确使用的页面类型吗?


当您将 ACF 与帖子一起使用时,您可以使用get_field()与您一样,但是当您将其与其他任何内容(例如分类法、用户或选项)一起使用时,您需要向 ACF 提供有关如何查找它的提示。在这种情况下,您需要告诉它您具体针对的分类法和术语。幸运的是,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 );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ACF 字段未显示在 WordPress 自定义分类页面上 的相关文章