如何使用ACF和Wordress从页面获取字段组ID?(How to get the Field Group ID from a page using ACF and Wordress?)

编程入门 行业动态 更新时间:2024-10-27 17:17:05
如何使用ACF和Wordress从页面获取字段组ID?(How to get the Field Group ID from a page using ACF and Wordress?)

我创建了许多字段组,并使用着名的高级自定义字段(ACF)插件使用' 显示此字段组,如果..页等于... X '。

我正在使用get_post_custom_keys()来显示页面中的所有自定义字段:

$custom_field_keys = get_post_custom_keys(45);

我硬编码了'45',它不是页面ID,而是字段组ID。 我很难获得与该页面关联的字段组的ID。

get_post_custom_keys($post_id); 将显示页面的自定义字段,而不是字段组。

我知道可能有多个字段组与一个页面相关联。

I created many field groups and used 'Show this field group if.. Page is equal to.. X' with the famous Advanced Custom Fields (ACF) plugin.

I'm using get_post_custom_keys() to show all the custom fields from a page:

$custom_field_keys = get_post_custom_keys(45);

I hardcoded the '45' which is not the page ID, but the Field Group ID. I'm struggling to get the ID of the field group associated with the page.

get_post_custom_keys($post_id); will show the custom fields for the page and not the field group.

I understand there might be multiple field groups associated with one page.

最满意答案

这是我的解决方案。 我直接查看数据库并查找当前页面的任何ACF规则,并获取该ID。

//Look for ACF rules for the current post $rows = $wpdb->get_results("SELECT * FROM wp_postmeta WHERE meta_key = 'rule'"); foreach ($rows as $row) { $values = unserialize($row->meta_value); if ($postid == $values["value"]) { $numberofacffield = $row->post_id; } } //Then read fields for the acf group id : $numberofacffield $custom_field_keys = get_post_custom_keys($numberofacffield);

Here is my solution. I look into the database directly and look for any ACF rules for the current page, and grab that ID.

//Look for ACF rules for the current post $rows = $wpdb->get_results("SELECT * FROM wp_postmeta WHERE meta_key = 'rule'"); foreach ($rows as $row) { $values = unserialize($row->meta_value); if ($postid == $values["value"]) { $numberofacffield = $row->post_id; } } //Then read fields for the acf group id : $numberofacffield $custom_field_keys = get_post_custom_keys($numberofacffield);

更多推荐

本文发布于:2023-07-23 22:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1238180.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   如何使用   页面   Wordress   ACF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!