0

Write a script to filter content by country.

I have problem Cannot use object of type Profile as array in .... on line 19

Part of code with error

global $user;
$country = "";
if($user->uid!=1 && $user->uid!=0){
  $user_full = profile2_by_uid_load($user->uid);
  if(!empty($user_full['client'])){
    $country_parent = taxonomy_get_parents($user_full['client']->field_clcountry['und'][0]['tid']);
3

This

$user_full = profile2_by_uid_load($user->uid);

Returns an object, which you are then accessing as an array:

$user_full['client']

Which is illegal in PHP. You should access objects as objects, e.g.

$user_full->client

Or whatever it might be for that object type.

|improve this answer|||||
  • Thanks, Script is work without error now, but function of filtration is missing. Here it full code of script, please anybody help. pastebin.com/9rgcTF39 – Alexander Kolovsky Feb 18 '15 at 15:19
  • 2
    Please ask another question, and include the relevant portions of code, error messages, descriptions of what you're trying to achieve, etc – Clive Feb 18 '15 at 15:34
1

You can also use this to load profile2

global $user;
$country = "";
if($user->uid!=1 && $user->uid!=0){
    $user_full = profile2_load_by_user($user);
    if(!empty($user_full['client'])){
        $country_parent = taxonomy_get_parents($user_full['client']->field_clcountry['und'][0]['tid']);
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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