[英]ACF field display on a page
我有一个问题。 我通过 ACF wordpress 插件创建了一个自定义字段。 它是自定义帖子类型类别的字段(可以说它是对该类别的附加描述)。 我试图通过这样的代码将它添加到我的页面:
$return_html.= '<h2 class="ppb_menu_title" ';
$return_html.= '>'.$menu_term->name.'</h2><br class="clear"/><br/>';
$displaytitle = the_field('category_subtitle');
$return_html.= '<div class="subtitledesc">'.$displaytitle.'</div>';
以下代码是整页代码的一部分,您可以在此处找到 [第 1712-1715 行]: https : //codeshare.io/50QzqL
我在做什么错?
带有单个参数的 get_field() 仅适用于循环 iirc 中的当前帖子,因此如果您尝试获取某个类别的数据,则必须提供一个目标。
您将需要类别的 termid(当您在分类法页面上时, $term = get_queried_object(); $termid = $term->term_id;
应该可以工作),然后像这样使用 get_field:
get_field( 'category_subtitle', "taxonomyname_$termid" );
get_field( 'category_subtitle', $term ); // if you have a term object
进一步阅读: https : //www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/
您需要使用get_field()
而不是the_field()
并包含术语 ID。
get_field()
返回一个值。
the_field()
一个值。
试试这个: get_field('category_subtitle', 'term_' . $menu_term->term_id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.