Home Forums Backend Issues (wp-admin) Adding image to the relational user select field


Adding image to the relational user select field

  • The objective is to change the content’s appearance for the select user box, in a relational – user field (picture attached).

    For this, I need to show an image uploaded as a custom field (through acf) to every user’s profile. But in a first approximation, I was trying to append the avatar, which is already in the user object, and that’s neither working for me.

    It works, when I add an img src, hardcoding it, in the array $this_users, inside the function get_choices located in the user.php file (line 153, for v5.2.5)

    All the filters that I’ve found are filtering the query, but not the output format in the administrator…

    Any ideas on how to achieve this? Is there any filter that I haven’t found?

    Many thanks.

  • After digging around in the code there does not appear to be a way to do this currently. What’s needed is a filter hook that allows the $this_users array to be altered so that the display value can be changed.

    I can’t say if this is something that the developer wants to add, I’m assuming he’d want it to work withing the existing hooks and I honestly don’t know if that can be done. I’ll see if I can get his attention/opinion.

  • Thanks for your time John,
    Indeed, it will be a good thing to have a filter hook to alter the $this_users array.
    I hope that Elliot consider it.

  • Hi guys

    Thanks for the feature request. I like it and will add it in!


  • Hi guys

    Just want to let you know I have added in some new filters for the user field and will be included in the next version of ACF PRO:

    – used to modify the text which is displayed for each user result

    $result = apply_filters("acf/fields/user/result", $result, $user, $field, $post_id);
    $result = apply_filters("acf/fields/user/result/name={$field['_name']}", $result, $user, $field, $post_id);
    $result = apply_filters("acf/fields/user/result/key={$field['key']}", $result, $user, $field, $post_id);

    – used to modify the columns which are searched

    $columns = apply_filters("acf/fields/user/search_columns", $columns, $search, $WP_User_Query, $field);
    $columns = apply_filters("acf/fields/user/search_columns/name={$field['_name']}", $columns, $search, $WP_User_Query, $field);
    $columns = apply_filters("acf/fields/user/search_columns/key={$field['key']}", $columns, $search, $WP_User_Query, $field);

    Hopefully these are self explanatory. I’ll add documentation soon


  • Can this type of filter please be added to the taxonomy and post object fields as well?

  • Hi @timothy_h

    Yep, this filter already exists for taxonomy:

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

You must be logged in to reply to this topic.