admin管理员组文章数量:1122846
How can I ensure that the data saved by an Advanced Custom Fields Relationship field, when on an Options page for a Post type, is separate?
Detail below:
I have an ACF field group, “Features”, containing a Relationship field.
It is intended to allow me to pre-set some featured posts for a couple of custom post types – “Reports” and “Articles”.
For those post types, in the same code that registers each post type, I have created an Options sub-page like this…
// Support showcase Features for this post type, via ACF
if( function_exists('acf_add_options_page') ) {
// add sub page
acf_add_options_sub_page(array(
'page_title' => 'Articles Features',
'menu_title' => 'Articles Features',
'menu_slug' => 'articles-features',
'capability' => 'edit_posts',
'parent_slug' => 'edit.php?post_type=article',
'position' => false,
'icon_url' => false
));
}
The same goes for “Reports”.
And then I apply the “Features” field group to both Options sub-pages – “Articles Features” and “Reports Features”.
The problem is… the data is the same. That is, the six Relationship posts set for “Reports Features” also show up in the Options sub-page for “Articles Features”. Changing one Relationship field overwrites the other.
How can I ensure that these two things are separate, so that I can save the features distinctly per post type, without recreating the field group?
How can I ensure that the data saved by an Advanced Custom Fields Relationship field, when on an Options page for a Post type, is separate?
Detail below:
I have an ACF field group, “Features”, containing a Relationship field.
It is intended to allow me to pre-set some featured posts for a couple of custom post types – “Reports” and “Articles”.
For those post types, in the same code that registers each post type, I have created an Options sub-page like this…
// Support showcase Features for this post type, via ACF
if( function_exists('acf_add_options_page') ) {
// add sub page
acf_add_options_sub_page(array(
'page_title' => 'Articles Features',
'menu_title' => 'Articles Features',
'menu_slug' => 'articles-features',
'capability' => 'edit_posts',
'parent_slug' => 'edit.php?post_type=article',
'position' => false,
'icon_url' => false
));
}
The same goes for “Reports”.
And then I apply the “Features” field group to both Options sub-pages – “Articles Features” and “Reports Features”.
The problem is… the data is the same. That is, the six Relationship posts set for “Reports Features” also show up in the Options sub-page for “Articles Features”. Changing one Relationship field overwrites the other.
How can I ensure that these two things are separate, so that I can save the features distinctly per post type, without recreating the field group?
Share Improve this question asked Apr 13, 2019 at 8:09 Robert AndrewsRobert Andrews 98819 silver badges42 bronze badges1 Answer
Reset to default 0The method to use is...
In the acf_add_options_sub_page
declaration, add 'post_id' => 'article'
as a parameter. (post_id)
This is how the field data, as entered on the Options page corresponding to my post type, will be saved.
On the display end, display using $featured_posts = get_field('featured_posts', 'article');
'article' and 'report' are both used.
In my case, at the display end, I use $queried_object->name
to dynamically infer either 'article' or 'report' post types.
Credit hube2
本文标签: Same ACF Relationship field for multiple Post Options subpages
版权声明:本文标题:Same ACF Relationship field for multiple Post Options sub-pages? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736293005a1929054.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论