Home Forums General Issues Make text field available depending on admin or front


Make text field available depending on admin or front

  • Hey guys,

    I would like to have a text field show up in admin, editable to a specific administrator but its value must be available/viewable to everyone on the front.

    So, I’m using the acf_render_field_setting() function together with a filter “acf/prepare_field” (explained here).

    The problem is I don’t know how to build the conditionals inside the if statement correct in order to achieve this. Can someone please help?

    Currently I have this:

    // Make sure to only show to administrators in admin but to everyone on the front
    add_filter('acf/prepare_field', 'my_admin_only_prepare_field');
    function my_admin_only_prepare_field( $field ) {
    	// bail early if no 'admin_only' setting
    	if( empty($field['admin_only']) ) return $field;
    	// return false if is not admin (removes field)
    	if( !current_user_can('administrator')) return false;
        if(!is_admin()) return $field;
    	// return
    	return $field;


  • Ok I solved it, kind of, by setting Show if rules to:

    Current User Role is equal to Administrator AND
    Post Type is equal to ‘my_custom_post_type’

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.