Support

Account

Home Forums General Issues Custom field setting of Relationship type not showing any values

Solved

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);  
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.