Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Members-Loop and Pagination issues


  • mdrabble
    Participant

    @mdrabble

    I have a customised members-loop page which works well except for the pagination links.

    If I click on the links it reloads the current page unless I right click and then open in new window and then the links work fine on the new window.

    The orginal code uses this code:
    <?php if ( bp_has_members( bp_ajax_querystring( 'members' ) ) ) : ?>

    I have changed my code to the following:
    <?php// if ( bp_has_members( my_custom_ids( 'Leaving Year', $_GET['alumniyear'] ) . '&populate_extras&type=alphabetical' ) ) : ?>

    If the alumniyear is present then it filters the members – if no alumniyear is select then all members are shown.

    I found the my_custom_ids on here and is shown below:

    function my_custom_ids( $field_name, $field_value = '' ) {
    
      if ( empty( $field_name ) )
        return '';
    
      global $wpdb;
    
      $field_id = xprofile_get_field_id_from_name( $field_name );
    
      if ( !empty( $field_id ) )
        $query = "SELECT user_id FROM " . $wpdb->prefix . "bp_xprofile_data WHERE field_id = " . $field_id;
      else
       return '';
    
      if ( $field_value != '' )
        $query .= " AND value LIKE '%" . $field_value . "%'";
          /*
          LIKE is slow. If you're sure the value has not been serialized, you can do this:
          $query .= " AND value = '" . $field_value . "'";
          */
    
      $custom_ids = $wpdb->get_col( $query );
    
      if ( !empty( $custom_ids ) ) {
        // convert the array to a csv string
        $custom_ids_str = 'include=' . implode(",", $custom_ids);
        return $custom_ids_str;
      }
      else
       return '';
    
    }
    ?>

    Anyone any idea on why this is happening?

    Thanks

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

  • Henry Wright
    Moderator

    @henrywright

    Try using bp_parse_args instead. That’s the way I’d recommend to filter the members loop (both pagination and the loop of members will be addressed)

    Using bp_parse_args() to filter BuddyPress template loops


    r-a-y
    Keymaster

    @r-a-y

    My guess is the javascript is causing a conflict.

    In your custom members loop, you can ensure that the JS doesn’t kick in if you change the pagination <div> class to something else.


    mdrabble
    Participant

    @mdrabble

    I dropped the above function and opted to use the following code in my bp-custom.php

    <?php
    function select_years( $retval ) {
    	global $wpdb;
    
    	$field_id = 6;
    	$value = $_GET['alumniyear']; 
    	
    	$query = "SELECT user_id FROM " . $wpdb->prefix . "bp_xprofile_data WHERE field_id = " . $field_id . " AND value = '" . $value . "'";
    
    	$year_ids = $wpdb->get_col( $query );
      
    	if ( !empty( $year_ids ) ) 
    		$retval['include'] = $year_ids;
    
    	return $retval;
    }
    ?>

    and on my members loop I have used the following.

    <?php
    if ( bp_ajax_querystring( 'members' ) =="") {
    	$queryString = "type=alphabetical&action=alphabetical&page=1";
    } else {
    	$queryString = bp_ajax_querystring( 'members' );
    }
    ?>
    
    <?php if ( bp_get_current_member_type() ) : ?>
    	<p class="current-member-type"><?php bp_current_member_type_message() ?></p>
    <?php endif; ?>
    
    <!-- Custom Code to show selected users -->
    
    <?php $year=$_GET['alumniyear'];?>
    <?php
    if ($year === NULL) {
        echo "<H3>All Alumni years</h3>";
    	 
    } else {
    	echo '<h3>Alumni Year: ' . $year .'</h3>';
    	add_filter( 'bp_after_has_members_parse_args', 'select_years' );
    }
    ?>

    It works better than the previous as I can now move between pages on all members….BUT…..

    when I am filtering the page, the page links move between pages but the filter is removed and the next page displays all members on next page.

    Again, if I right click on in new windows/tab the page links work perfectly.

    Any ideas/suggestions welcome 🙂


    mdrabble
    Participant

    @mdrabble

    I’m happy to PM a test account (non-admin) to see what is happening if that helps.


    mdrabble
    Participant

    @mdrabble

    Anyone able to offer any suggestions?

    Thanks in advance

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar