Skip to:
Content
Pages
Categories
Search
Top
Bottom

Members Page custom URL with select box value


  • aaronkine
    Participant

    @aaronkin

    How can i make a URL Link that will select from the pull down menu?

    In my functions.php I have created custom Sorts added to the existing “Order By:” drop down menu. So my Order By: has these choices; Last Active, Newest Registered, Alphbetical, Organization, Funder, Company. How can i create a URL Link that will choose one of these upon page load?

    After searching i think i need to change the Form method to GET and add some javascript on the page. Then use a URL similar to this http://nprnsb.org/members?members-order-by=Organization.

    Any guidance would be greatly appreciated.

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

  • ch1n3s3b0y
    Participant

    @ch1n3s3b0y

    Hi @aaronkin

    Did you actually manage to get your custom ‘sorts’ to actually sort the data or does it just filter it? I have managed to add a new option to ‘Order By’ which I can use to filter results, but it won’t sort the data by a profile field. It will only accept the current types, i.e. ‘alphabetical’ ‘last active’ etc.


    aaronkine
    Participant

    @aaronkin

    Yes. I have it filter by User Role (wp_capabilities) then sort the list by username. I barely got this working and it took me forever. I would like to also Sort By a xprofile field but i dont know how. I’m sure this code gets me really close but i’m just not experienced enough to figure this out just yet.

    here’s what i have in my functions.php
    This will add 3 drop down items, Organizations, Funders, Company. this sorts by User Role. when people signup for my site they choose the appropriate Reg. Form (each form assigns user role).

    If you ever find out HOW TO SORT BY xProfile Field, please post here.

    add_action( 'bp_members_directory_order_options', 'add_sortby_role' );
    function add_sortby_role() { ?>
    	<option value="sort-organization">Organization</option>
    	<option value="sort-funder">Funder</option>
    	<option value="sort-company">Company</option>
    
    	<?php
    }
    add_action( 'bp_pre_user_query', 'mysortbyorganization' );
    add_action( 'bp_pre_user_query', 'mysortbyfunder' );
    add_action( 'bp_pre_user_query', 'mysortbycompany' );
    
    function mysortbyorganization( $BP_User_Query ) {
    	// Only run this if one of our custom options is selected
    	if ( in_array( $BP_User_Query->query_vars['type'], array( 'sort-organization' ) ) ) {
    		global $wpdb;
    
    		// Adjust SELECT
    		$BP_User_Query->uid_clauses['select'] = "
    SELECT u.ID, u.user_login, u.user_nicename, u.user_email
    FROM $wpdb->users u
    INNER JOIN $wpdb->usermeta m ON m.user_id = u.ID
    WHERE m.meta_key = 'wp_capabilities'
    AND m.meta_value LIKE '%organization%'
    ORDER BY u.user_nicename
    ";
    	}
    }
    function mysortbyfunder( $BP_User_Query ) {
    	// Only run this if one of our custom options is selected
    	if ( in_array( $BP_User_Query->query_vars['type'], array( 'sort-funder' ) ) ) {
    		global $wpdb;
    
    		// Adjust SELECT
    		$BP_User_Query->uid_clauses['select'] = "
    SELECT u.ID, u.user_login, u.user_nicename, u.user_email
    FROM $wpdb->users u
    INNER JOIN $wpdb->usermeta m ON m.user_id = u.ID
    WHERE m.meta_key = 'wp_capabilities'
    AND m.meta_value LIKE '%funder%'
    ORDER BY u.user_nicename
    ";
    	}
    }
    function mysortbycompany( $BP_User_Query ) {
    	// Only run this if one of our custom options is selected
    	if ( in_array( $BP_User_Query->query_vars['type'], array( 'sort-company' ) ) ) {
    		global $wpdb;
    
    		// Adjust SELECT
    		$BP_User_Query->uid_clauses['select'] = "
    SELECT u.ID, u.user_login, u.user_nicename, u.user_email
    FROM $wpdb->users u
    INNER JOIN $wpdb->usermeta m ON m.user_id = u.ID
    WHERE m.meta_key = 'wp_capabilities'
    AND m.meta_value LIKE '%company%'
    ORDER BY u.user_nicename
    ";
    	}
    }
    

    danbp
    Participant

    @danbp

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Members Page custom URL with select box value’ is closed to new replies.
Skip to toolbar