[英]ACF field display on a page
I've got an issue.我有一个问题。 I've created a custom field via ACF wordpress plugin.
我通过 ACF wordpress 插件创建了一个自定义字段。 Its a field to custom post type categories (lets say its an additional description to the category).
它是自定义帖子类型类别的字段(可以说它是对该类别的附加描述)。 I've tried to add it to my page via such code:
我试图通过这样的代码将它添加到我的页面:
$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>';
below code is a part of full page of code which you can find here [lines 1712-1715]: https://codeshare.io/50QzqL以下代码是整页代码的一部分,您可以在此处找到 [第 1712-1715 行]: https : //codeshare.io/50QzqL
what i am doing wrong?我在做什么错?
get_field() with a single parameter only works on the current post within the loop iirc, so you will have to provide a target if you're trying to get data for a category.带有单个参数的 get_field() 仅适用于循环 iirc 中的当前帖子,因此如果您尝试获取某个类别的数据,则必须提供一个目标。
You'll need the termid of your category (when you're on a taxonomy-page, $term = get_queried_object(); $termid = $term->term_id;
should work), then use get_field like so:您将需要类别的 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
Further reading: https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/进一步阅读: https : //www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/
You'll want to use get_field()
instead of the_field()
and include the term ID.您需要使用
get_field()
而不是the_field()
并包含术语 ID。
get_field()
returns a value. get_field()
返回一个值。
the_field()
echoes a value. the_field()
一个值。
Try this: get_field('category_subtitle', 'term_' . $menu_term->term_id)
试试这个:
get_field('category_subtitle', 'term_' . $menu_term->term_id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.