Home › Forums › General Issues › Custom field setting of Relationship type not showing any values
I am trying to register a custom field setting of the ‘Relationship’ type in order to create more granular conditional logic for displaying/hiding fields. Specifically, I would like to select one or more pages on which to hide the field(s) in question. Here is the code I am registering the field with:
acf_render_field_setting( $field, array(
'label' => __('Hide on Pages', 'jdmn'),
'instructions' => __('Hide this field on the following pages.', 'jdmn'),
'name' => 'hide_on_pages',
'type' => 'relationship',
'post_type' => array(
0 => 'page',
),
'taxonomy' => '',
'filters' => '',
), true);
While the new settings field shows up properly after registering it, it does not display any values/pages. Could anyone tell me what I’m doing wrong and/or point me towards a solution? In the meanwhile, I will try to dynamically populate the fields choices array and see if that works.
Thanks very much in advance.
In the meanwhile, I will try to dynamically populate the fields choices array and see if that works.
While this didn’t solve my original problem of the choices/pages not showing up in a ‘Relationship’ type field, the alternative approach described above worked just fine for what I was trying to achieve:
acf_render_field_setting( $field, array(
'label' => __('Hide on Pages', 'jdmn'),
'instructions' => __('Hide this field on the following pages.', 'jdmn'),
'name' => 'hide_on_pages',
'type' => 'select',
'choices' => (function(){
$array = array();
$pages = get_pages();
foreach( $pages as $page ) {
$array[$page->ID] = $page->post_title;
}
return $array;
})(),
'default_value' => null,
'allow_null' => 1,
'multiple' => 1,
'ui' => 1,
), true);
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.