BuddyDev

Search

xProfile fields – Fetch profilgroups in member loop

  • Participant
    Level: Initiated
    Posts: 2
    Tom on #18940

    Hey guys,

    i am creating a new display style for the member loop. (See Picture)
    It is actually working with my old code, but the code is so horrible.. I am trying to get it more efficient, but i am failing.

    Picture: https://imgur.com/a/JtN9keX

    The Project:
    – We have 12 Member Types with 1 specific Fieldgroup for each Member Type.
    – The Users can (as example) search for Illustrators and get their whole Profil Informations in the
    member loops, displayed as icons.

    My New Attempt:

    // Fieldgroups as array
    $membertypes = array(
    	"Cosplayer",
    	"Musiker",
    	"Redakteure",
    	"Fotografen",
    	"Autoren",
    	"Darsteller",
    	"Illustratoren",
    	"Website Veranstalter",
    	"Händler",
    	"Gastronomen",
    	"Handwerker"
    );
    
    // Different Fields that has to displayed in the loop
    $profileComponents = array(
    	"Website",
    	"Facebook",
    	"Instagram",
    	"Twitter",
    	"E-Mail",
    	"Telefon",
    	"PLZ"
    );
    
    foreach($membertypes AS $name) {
    	if((strpos($_SERVER['REQUEST_URI'], $name)))
    	{
    		foreach($profileComponents AS $component) {
    										// Doesnt work? Field name are: Website Cosplayer , Facebook Cosplayer e.t.c ... 
    			if(xprofile_get_field_data($component.$name, bp_get_member_user_id() ) != '') {
    
    				if($component == "Website") {
    					?> <span id="homepageicon"> <a href="<?php echo xprofile_get_field_data($component . $name, bp_get_member_user_id() ); ?>" target="_blank"> <i class="fas fa-home"></i></a></span> <?php
    				}
    
    				if($component == "Facebook") {
    					?> <span id="facebookicon"><a href="<?php echo xprofile_get_field_data($component . $name, bp_get_member_user_id() ); ?>" target="_blank"> <i class="fab fa-facebook"></i></a></span> <?php
    				}
    
    				if($component == "Instagram") {
    					?> <span id="facebookicon"><a href="<?php echo xprofile_get_field_data( $component . $name , bp_get_member_user_id() ); ?>" target="_blank"> <i class="fab fa-instagram"></i></a></span> <?php
    				}
    
    				if($component == "Twitter") {
    					?> <span id="facebookicon"><a href="<?php echo xprofile_get_field_data( $component . $name , bp_get_member_user_id() ); ?>" target="_blank"> <i class="fab fa-twitter"></i></a></span> <?php
    				}
    
    				if($component == "PLZ") {
    					?> <span id="plzicon"><i class="fas fa-map-marker-alt"></i> <?php echo xprofile_get_field_data( $component . $name , bp_get_member_user_id() ); ?></span> <?php
    				}
    
    				if($component == "E-Mail") {
    					?> <div id="mailreturn" style="display:none">
    						<?php echo '<p id="mailreturncheck">'. xprofile_get_field_data( $component . $name , bp_get_member_user_id() ) . '</p>'; ?>
    						</div> <?php
    				}
    
    				if($component == "Telefon") {
    					?> <div id="mobilnummer" style="display:none">
    					<?php echo '<p id="mobilnummercheck">'. xprofile_get_field_data( $component . $name , bp_get_member_user_id() ) . '</p>'; ?>
    					</div> <?php
    				}
    			}
    		}
    	}
    }

    Some Ideas how to Fetch through efficient with a foreach and some conditions?
    I am very thankfull for you help!

    Greetings,
    Tom

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #18951

    Hi Tom,
    Welcome to BuddyDev.

    I don’t think you need the above code.

    Is your goal to display the fields in profile card as shown on the image?

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 2
    Tom on #18962

    Hello Brajesh,
    thank you!

    No, it is allready showing in the Profilcard. Thats not the goal.

    I created a custom member-Loop for a directory.
    (Maybe you can take a quick look at it? -> https://www.myfantasyworld.de/kuenstler-dienstleister/
    (Maybe better to understand.)

    You can select the Member Type and it will show you all registered Members with that Type.
    Then it displays the Informations of the Users as Icons. (Facebook, Instagram, Website e.t.c)

    It actually works, but its very slow and ugly. (1200 rows of code..)
    I thought there must be an easier and shorter way to fetch through the xProfile Fields. But my attempt (See Code above) Dont work.

    Regards
    Tom

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #18965

    Hi Tom
    I have a question.

    The BuddyPress Member Types provide the directory support out of the box.

    What is the reason that you are creating your own custom loops.

    If I had to tackle it, I will link to default BuddyPress Members Directory and then use hook “bp_directory_members_item” to create a box and add extra profile details.

    Also, the above loop can be simplified in that case. You fetch the member type of the current user in the loop

    
    
    $member_type = bp_get_member_type(bp_get_member_user_id(), true) 
    
    

    and write a function to generate the details for that user. In your above code, you might want to add a space to $component.$name like

    
    
    $component. ' ' . $name
    
    

    As your Field Names have space.

    Hope that helps you with the right direction.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 2
    Tom on #18997

    Hi Brajesh,

    thank you very much for that Idea.

    i will try it tommorrow!

    Regards
    Tom

You must be logged in to reply to this topic.

This topic is: not resolved