0

I am able to find the username. From the username I need to fill the user reference field.

Is there a way to get the user reference field value from username?

Example:

I have username: abc
I need Reference field value: Abc(201)

user_load_by_name('admin')

stdClass Object
(
    [uid] => 1
    [name] => admin
    [pass] => $S$DYk/jJiQjg07cciSAeU2EeP3XVMm/WhWHG19rA1iQf/FIqdOmY5p
    [mail] => [email protected]
    [theme] => 
    [signature] => 
    [signature_format] => 
    [created] => 1469189190
    [access] => 1511853833
    [login] => 1511853621
    [status] => 1
    [timezone] => Asia/Kolkata
    [language] => 
    [picture] => 
    [init] => [email protected]
    [data] => 
    [uuid] => 77ef7473-31cd-432e-ace6-26f1b075abb5
    [roles] => Array
        (
            [2] => authenticated user
            [3] => administrator
        )

    [rdf_mapping] => Array
        (
            [rdftype] => Array
                (
                    [0] => sioc:UserAccount
                )

            [name] => Array
                (
                    [predicates] => Array
                        (
                            [0] => foaf:name
                        )

                )

            [homepage] => Array
                (
                    [predicates] => Array
                        (
                            [0] => foaf:page
                        )

                    [type] => rel
                )

        )

)
1
  • Hmmm... It looks like you're not getting any fields. If you run $account = user_load_by_name($name); user_load($account->uid);, does it give you the fields? I don't think you should need to load the user twice though. Commented Nov 28, 2017 at 7:35

1 Answer 1

0

You can do this with user_load_by_name($name).

Once you load the user object you should be able to access the reference field normally.

1
  • Thanks @Patrick for quick reply. I have updated the question with the result of user_load_by_name($name). Actually i am not getting the reference field value.
    – DRUPWAY
    Commented Nov 28, 2017 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.