ACF字段未显示在wordpress自定义分类页面上 [英] ACF fields not showing on a wordpress custom taxonomy page

查看:184
本文介绍了ACF字段未显示在wordpress自定义分类页面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自定义分类页面上显示ACF遇到麻烦。

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

自定义税为目的地,页面为taxomony-destinations.php,该字段为称为 destination_landing_image。我正在尝试在 mysite.com/destinations/coutryname上显示它,如下所示:

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; ?>

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

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?

推荐答案

在帖子中使用ACF时,您只能使用 get_field()不变,但是当将它与其他分类法,用户或选项一起使用时,需要向ACF提供有关如何查找它的提示。在这种情况下,您需要告诉它具体针对的分类法和术语。幸运的是,WordPress和ACF都使此操作变得非常简单:

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

这篇关于ACF字段未显示在wordpress自定义分类页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆