Home › Forums › Backend Issues (wp-admin) › 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!
Cheers
E
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:
result
– 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);
search_columns
– 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
Thanks
E
Can this type of filter please be added to the taxonomy and post object fields as well?
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’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.