gpt4 book ai didi

ACF get custom fields for a tag(ACF获取标记的自定义字段)

转载 作者:bug小助手 更新时间:2023-10-25 18:09:20 26 4
gpt4 key购买 nike



I'm using ACF to create new custom fields to include more info in tags. Then I want to retrieve in the tag page like this:

我正在使用ACF创建新的自定义字段,以便在标签中包含更多信息。然后,我想在标记页面中检索如下内容:


$term_id = get_queried_object()->term_id;
$posts_ids = isset ($term_id) ? get_fields('articulos_destacados', 'taxonomy_'.$term_id, false) : null;

But nothing is retrieved. What am I doing wrong?

但什么也没有被取回。我做错了什么?


更多回答

$term_id will always return as set, since get_queried_object if nothing is found returns null, so therefore it's still set. Also, get_fields can accept the term object. So you don't need the term_id.

$Term_id将始终作为set返回,因为如果未找到任何内容,则Get_Query_Object返回NULL,因此仍为set。此外,get_field可以接受术语Object。因此,您不需要术语_id。

$term = get_queried_object(); $posts_ids = isset ($term_id) ? get_field('articulos_destacados', $term) : null; I've also try this, but I get an error saying there is no 'articulos_destacados' field (it is the one I've defined in ACF).

$TERM=GET_QUERED_OBJECT();$POSTS_IDS=isset($TERM_id)?GET_FIELD(‘ARITEROS_DESERCADOS’,$TERM):空;我也尝试过这个方法,但我收到一个错误,指出没有‘ARETETOS_DESTARCOS’字段(这是我在ACF中定义的字段)。

Do a var_dump( get_fields($term) ) and see what is returned

执行var_ump(get_field($Term))并查看返回的内容

It worked like this: $term = get_queried_object(); $posts_ids = get_fields('term_'.$term->term_id, false); Thanks a lot.

它是这样工作的:$Term=Get_Query_Object();$POSTS_IDs=Get_field(‘Term_’.$Term->Term_id,False);非常感谢。

优秀答案推荐

in ACF you should call it prefixed by taxonomy name before the term_id

在ACF中,您应该在术语_id之前加上分类法名称作为前缀


Tags (post_tag):
get_fields('field_name', 'post_tag_'.$term_id, false)

标签(Post_Tag):get_field(‘field_name’,‘post_tag_’.$Term_id,FALSE)


Categories (category):
get_fields('field_name', 'category_'.$cat_id, false)

Categories(类别):get_field(‘field_name’,‘ategory_’.$cat_id,FALSE)


The sloution to your code:

您的代码的解决方案:


$posts_ids = isset ($term_id) ? get_fields('articulos_destacados', 'post_tag_'.$term_id, false) : null;

$POSTS_IDS=isset($Term_id)?GET_FIELDS(‘ARITEROS_DESTCAROS’,‘POST_TAG_’.$Term_id,FALSE):空;


更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com