acf/fields/user/result

Last updated Jul 14, 2023
Link to heading

Description

Filters the text displayed for each user.

Link to heading

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.
Link to heading

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.
Link to heading

Example

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

Link to heading

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;

}
Supercharge Your Website With Premium Features Using ACF PRO

Speed up your workflow and unlock features to better develop websites using ACF Blocks and Options Pages, with the Flexible Content, Repeater, Clone, Gallery Fields & More.

Explore Features View Pricing

PRO Features
ACF Blocks
Options Pages
PRO Fields
Repeater
Flexible Content
Gallery
Clone
Link to heading

Related

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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.