Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding new option in “order by” section in members-loop


  • fidelduque
    Participant

    @fidelduque

    Hi guys, I’m trying to create a new “order by” item in members loop. I’ve used this code in functions.php to change the sorting alphabetically functionality:

    /* Sorting by lastname in buddypress*/
    function alphabetize_by_last_name( $bp_user_query ) {
        if ( 'alphabetical' == $bp_user_query->query_vars['type'] ){
    		
            $bp_user_query->uid_clauses['orderby'] = "ORDER BY (select value from pwisa_bp_xprofile_data where field_id = 2 and user_id = u.ID) ";
    	}		
    }
    add_action ( 'bp_pre_user_query', 'alphabetize_by_last_name' );

    That code works. But now I want to use another item.

    I’ve created the new item in my customized: /members/index.php file.

    <option value="country">[:es]Por PaĆ­s[:en]By Country[:pb]By Country[:]</option>

    But if i do this in my functions.php

    /* Sorting by lastname in buddypress*/
    function alphabetize_by_last_name( $bp_user_query ) {
    	error_log("---" . $bp_user_query->query_vars['type']);
        if ( 'alphabetical' == $bp_user_query->query_vars['type'] ){
    		
            $bp_user_query->uid_clauses['orderby'] = "ORDER BY (select value from pwisa_bp_xprofile_data where field_id = 2 and user_id = u.ID) ";
    	}	
    	if('country' == $bp_user_query->query_vars['type'] ){
    		$bp_user_query->uid_clauses['orderby'] = "ORDER BY (select value from pwisa_bp_xprofile_data where field_id = 7 and user_id = u.ID) ";
    	}
    }
    add_action ( 'bp_pre_user_query', 'alphabetize_by_last_name' );

    It won’t work. the variable $bp_user_query->query_vars[‘type’] is alwas getting: alphabetical value.

    What can I check or change to fix this? help.

  • You must be logged in to reply to this topic.
Skip to toolbar