我创建了许多字段组,并使用着名的高级自定义字段(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);更多推荐
发布评论