acf/fields/user/result

Last updated Jul 14, 2023

Description

Filters the text displayed for each user.

Parameters

apply_filters( 'acf/fields/user/result', $text, $user, $field, $post_id );
  • $text (string) The text displayed for this user.
  • $user (WP_User) The user object.
  • $field (array) The field array containing all settings.
  • $post_id (WP_Post) The post ID where the value is saved.

Modifiers

This filter provides modifiers to target specific fields. The following filter names are available:

  • acf/fields/user/result Applies to all fields.
  • acf/fields/user/result/name={$name} Applies to all fields of a specific name.
  • acf/fields/user/result/key={$key} Applies to all fields of a specific key.

Example

This example demonstrates how to return user meta, in this case the user’s preferred_name_field appended to the standard result.

functions.php

<?php
add_filter('acf/fields/user/result/name=subscriber_field_name', 'my_acf_fields_user_result', 10, 4);

function my_acf_fields_user_result( $text, $user, $field, $post_id ) {

    //Retrieve the preferred name field value from user
    $recipient = get_field( 'preferred_name_field', 'user_' . $user->ID );

    $text .= ' (' . $recipient . ')';

    return $text;

}