Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add custom xprofile links


  • barodscheff
    Participant

    @barodscheff

    Hi guys!

    You already helped me to remove the xprofile links and to display a filtered view of all members on my homepage (https://buddypress.org/support/topic/display-filtered-overview-of-members/#post-231596).

    So I hope you can help me once again.
    I’ve build a network for athletes. Among many other profile fields every athlete have a profile field called “gender” and “sport”. As already mentioned I’ve filtered this on my landing page for a nice overview. The code for female athletes looks like this:

    <?php
    	$sports = array('Archery', 'Badminton', 'Baseball', 'Basketball', 'Bowling', 'Equestrian', 'Fencing', 'Field Hockey', 'Football', 'Golf', 'Gymnastics', 'Ice Hockey', 'Lacrosse', 'Rifle', 'Rowing', 'Skiing (Cross Country)', 'Skiing (Downhill)', 'Soccer', 'Softball', 'Squash', 'Swimming and Diving', 'Tennis', 'Track and Field', 'Volleyball', 'Water Polo', 'Wrestling');
    	$sportsSize = sizeof($sports);
    	$femaleCounter = 0;
    	for ($i = 0; $i < $sportsSize; $i++) {
    		$femaleSport = $wpdb->get_var( "SELECT COUNT(user_id) FROM ar_bp_xprofile_data WHERE value = 'female' AND user_id IN (SELECT user_id FROM ar_bp_xprofile_data WHERE value = '" . $sports[$i] . "')" );
    		if ($femaleSport != 0) {
    			echo '<p>' . $sports[$i] . ' (' . $femaleSport . ')</p>';
    			$femaleCounter++;
    		}
    	}
    	if ($femaleCounter == 0) {
    		echo '<p>Sorry, there are no female athletes registered yet.</p>';
    	}
    ?>

    In the Frontend it could look like this:

    Female:
    Baseball(4)
    Basketball(2)
    Soccer(8)

    Male:
    Baseball(20)
    Basketball(30)
    Tennis(5)

    Now I would like to generate links on the sports as it’s automatically done with profile fields.

    I think there are two problems:
    1) I have already removed xprofile links in profile/members loop.
    2) The sports are not in the members or profile loop.

    Can you help me?

Viewing 4 replies - 1 through 4 (of 4 total)

  • Henry Wright
    Moderator

    @henrywright

    Hi @barodscheff

    Can you clarify exactly what you’d like to link and where you’d like to link to?


    barodscheff
    Participant

    @barodscheff

    Yes, of course.
    I would like to link the sports which are profile fields. For instance if you click on male/Basketball you should get an overview of all members who are also male and do the sport Basketball.
    This is automatically possible in members loop but I would like to have it on my landing page.

    I hope it’s clear now.


    Henry Wright
    Moderator

    @henrywright

    Right. In that case, you can just modify the output of your for loop. For example:

    for ( $i = 0; $i < $sportsSize; $i++) {
    
        // For this particular $i, get the URL here and store it in a $url variable. You may need to query the db again? i.e. where will you get the URL from, or where are you storing it?
    
        $femaleSport = $wpdb->get_var( "SELECT COUNT(user_id) FROM ar_bp_xprofile_data WHERE value = 'female' AND user_id IN (SELECT user_id FROM ar_bp_xprofile_data WHERE value = '" . $sports[$i] . "')" );
    
        if ($femaleSport != 0) {
            // Update the output of the loop to include hyperlink markup.
            echo '<p><a href="' . $url . '">' . $sports[$i] . ' (' . $femaleSport . ')</a></p>';
            $femaleCounter++;
        }
    }

    barodscheff
    Participant

    @barodscheff

    Thank you for the answer but my problem is the url. I have no idea how to generate the custom url.

    If I use the build in function (xprofile_links) in members area and click e.g. on ‘Soccer’ I will get a new page with all members who also have soccer as their sport. The url is like ‘my-url/members/?s=Soccer’. But I need two filters. One for ‘sport’ and one for ‘gender. Something like ‘my-url/members/?s=Soccer&s=male’ is not working.

    Maybe you know the right url structure?

    Anyway I think this in not the best solution. Is there a way to use the xprofile_link function which is build in? I removed it in the members area with

    function remove_xprofile_links() {
       remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
    }
    add_action( 'bp_init', 'remove_xprofile_links' );	

    But I would like to apply it on my landing page. Is that possible?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add custom xprofile links’ is closed to new replies.
Skip to toolbar