I want to load users with profile2 fields as a custom function like:
function mytheme_getCandidatesHome() { $ type = 'candidata'; $ users = db_select('users', 'u') ->fields('u', array('uid')) ->range(0,8) ->orderRandom() ->execute() ->fetchAll(); $ str = '<!--<ul id="carousel_inner">--><ul>'; foreach($ users as $ u) { $ profile_data = profile2_load_by_user($ u->uid, $ type); $ str.= '<li class="mmmd-candidate-item">'; $ str.= '<div class="image">'; $ image = (!empty($ profile_image)) ? '/sites/default/files/'.$ profile_image : mmmd_get_noimage_profile(); $ str.= '<div style="background:url('.$ image.') no-repeat; background-size:cover;" class="profile-image"></div>'; $ str.= '</div>'; $ str.= '<div class="data">'; $ str.= '<div class="name"> '.ucwords(mb_strtolower($ profile_name)).'</div>'; $ str.= '<div class="title">'.((!empty($ u->field_candidata_postulacion)) ? $ u->field_candidata_postulacion : '---').'</div>'; $ str.= '<div class="location">'.((!empty($ u->field_candidata_lugar_postul)) ? $ u->field_candidata_lugar_postul : '---').'</div>'; $ str.= '</div>'; $ str.= '</li>'; } $ str.= '</ul>'; print $ str; }
And why profile2_load_by_user($ u->uid, $ type)
doesn’t work? Please help! The function is running on template.php