Hi everyone,
I have custom fields on a specific type of posts.
One of those fields is a type: User.
It offers a dropdown with a search field that returns users.
The results are shown like that :
Firstname Lastname (nickname)
Firstname Lastname (nickname)
Firstname Lastname (nickname)
I would like to add the email next to nickname.
What would be the best way to do that?
Thank you
There is a filter hook acf/fields/user/result, it is not documented, but it works the same as acf/fields/post_object/result
Thank you!
For others here is what I did.
add_filter('acf/fields/user/result', 'my_acf_fields_user_text', 10, 4);
function my_acf_fields_user_text($text, $user, $field, $post_id){
$args = array(
'post_type' => 'MY_POST_TYPE',
'order' => 'DESC',
'posts_per_page' => 5,
'paged' => 1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'user_name',
'value' =>$user->ID,
'compare' => '=',
),
array(
'key' => 'META_TO_COMPARE',
'value' =>0,
'compare' => '=',
),
),
);
$posts = new WP_Query( $args );
$nb_posts = $posts->found_posts;
$text .= ' - ' . $user->user_email . ' [' . $nb_posts . ' posts]';
return $text;
}