Randomly displaying a member
Posted: 15 June 2009 03:57 AM   [ Ignore ]
Newbie
Rank
Total Posts:  8
Joined  2007-11-04

Hi,

Below is my code for trying to display a single member, at random, from my member group (id “5”) based on whether a custom member field (trader_company) has been filled in.

I know for a fact that of the members I currently have all have the custom member field filled in but for some reason I’m getting mostly blanks and the occasional member data.

Any help greatly appreciated. The code below is embeded into another page if that makes any difference.

{exp:user:users group_id="5" orderby="random" limit="1"}
{if trader_company 
!= ""}
    
<h2><a href="{path=">{trader_company}</a></h2>
{/if}    
    {trader_bio}
    
</div>
    
{if photo_filename}<img src="{photo_url}{photo_filename}" width="{photo_width}" height="{photo_height}" />{/if}
{
/exp:user:users} 
Profile
 
 
Posted: 16 June 2009 10:52 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8281
Joined  2006-10-18

Hi smdnetau,

Well looking at your code, I see it is possible there could be “blanks”. wink

With those conditionals, if neither match, the only thing left to display is “{trader_bio}”, IF there’s data for it wink

 Signature 
Profile
 
 
Posted: 16 June 2009 02:48 PM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  8
Joined  2007-11-04

Sorry that was the wrong code block. Is a SQL query the better way to go?

{exp:user:users group_id="5" orderby="random" limit="1"}
{if trader_company 
!= ""}
    
<h2><a href="{path=">{trader_company}</a></h2>
    
{trader_bio}
    {if photo_filename}
<img src="{photo_url}{photo_filename}" width="{photo_width}" height="{photo_height}" />{/if}
{
/if}    
{
/exp:user:users} 
Profile
 
 
Posted: 17 June 2009 09:23 AM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8281
Joined  2006-10-18

No, because conditionals are parsed AFTER parameters wink

So while the loop is returning 1 result based on the parameters, the conditionals are only showing or HIDING that result, whether it matches the conditional or not smile

What you need to do is scrap the conditional, and come up with a way to filter with a parameter, such as the member field search parameter:

custom_member_field="trader_company|something"
filter_method="any" 

A quick guess tells me the logic may not work for what you currently have, so you might need to base it on a different field, or add a new field that collects a SAME value for every member when selected in their profile wink

 Signature 
Profile
 
 
Posted: 17 June 2009 06:49 PM   [ Ignore ]   [ # 4 ]
Newbie
Rank
Total Posts:  8
Joined  2007-11-04

Thanks for your help!

As per your suggestion, I created a common field for all members to fill in. If this value is ‘Yes’ then the profile is displayed.

Code below for posterity:

{exp:user:users group_id="5" orderby="random" limit="1" custom_member_field="trader_visibility|Yes" filter_method="exact" }
    
<h2><a href="{path=">{trader_company}</a></h2>
    
{trader_bio}
    {if photo_filename}
<img src="{photo_url}{photo_filename}" width="{photo_width}" height="{photo_height}" />{/if}
{
/exp:user:users} 
Profile
 
 
Posted: 18 June 2009 01:33 PM   [ Ignore ]   [ # 5 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  8281
Joined  2006-10-18

Beauty! wink

 Signature 
Profile