Skip to:
Content
Pages
Categories
Search
Top
Bottom

Remove “order by” filter from members loop using custom hook


  • Agência HypeLab
    Participant

    @hackaust

    Hello guys.I must remove the “order by” in the loop members because i have one custom function that generate the include parameter with the users on correct order. This is necessary because these custom function perform complex sql select with cross join and the devil.

    I tried to use the following hook in my child functions.php:

    function remove_orderby( $bp_user_query ) {
    $bp_user_query->uid_clauses['orderby'] = "";
    }
    add_action ( 'bp_pre_user_query', 'remove_orderby' );

    This not work. Is possible implement an hack to this approach?

    Thanks _/\_

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

  • shanebp
    Moderator

    @shanebp

    Try changing the priority from the default of 10.
    For example:
    add_action ( 'bp_pre_user_query', 'remove_orderby', 99 );
    or
    add_action ( 'bp_pre_user_query', 'remove_orderby', 2 );


    shanebp
    Moderator

    @shanebp

    Or try using the filter:

    $sql = apply_filters_ref_array( 'bp_user_query_uid_clauses', array( $sql, &$this ) );


    Agência HypeLab
    Participant

    @hackaust

    Hello shanebp,
    Thank you for response. Change the priority dont change the behaviour. When i declare the action to remove_orderby in all situations dont retrieve users on frontend.
    The next try i dont understand in which context i have try this

    For a better understanding, my code basically works as follows:


    $empresas = get_empresas();
    if (!empty($empresas) and bp_has_members($empresas . "&per_page=28")){
    echo "<div id='buatp_members' class='grid_view'>";
    ...

    The $empresas get the complete include parameter like this: include=1000,1001,1002
    The next line begins the build of user list content.

    is possible correctly extend the bp_has_members() function to get this approach?


    shanebp
    Moderator

    @shanebp

    Have you read this codex page?
    Note the section at the bottom: ‘Preserve the Order’


    Agência HypeLab
    Participant

    @hackaust

    Thanks for your support Shanebp.
    I undestand the example in the codex page but im not sure in how to implement this because i pass the complete string “include=” to function bp_has_members like described above.

    I need instance the class in exemple and call bp_has_members without parameters?


    Agência HypeLab
    Participant

    @hackaust

    Guys,
    I need some help with this. I have no idea how to implement this solution using the hook bp_pre_user_query_construct. Please help me with this issue at least some basic example.
    My problem is that i call bp_has_members on the loop like this:
    $profissionais = "include=1,2,3,4,5,6";
    if (!empty($profissionais) and bp_has_members($profissionais . "&per_page=28")){

    I dont have ideia in how to call bp_has_member in bp_pre_user_query_construct context .

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Remove “order by” filter from members loop using custom hook’ is closed to new replies.
Skip to toolbar