0

I'm trying to filter the Buddypress Members loop to show only members that have published posts. I got the directory to display the members I wanted using the following code. However, by eliminating the standard bp_ajax_querystring( 'members' ) part after the bp_has_members, the search functionality on the page won't work. I can't seem to get the directory to display the results with both the bp_ajax_querystring( 'members' ) and the below filters. Any ideas?

<?php do_action( 'bp_before_members_loop' ); ?>

<?php 

    // The Query
    $user_query = new WP_User_Query( array( 'has_published_posts' => true) );

    // User Loop
    $published_users = array();

    if ( ! empty( $user_query->results ) ) {
        foreach ( $user_query->results as $user ) {
        $published_users[] = $user->ID ;

    }
    } else {
    }

    $usersimploded = implode(",",$published_users);
    ?>

    <?php if ( bp_has_members(array('include' => $usersimploded, 'type'=>'alphabetical', 'exclude' => '1,2,62'))) : ?>
  • I edited the post to show what I got to partially work. I can't figure out how to fit the original bp_ajax_querystring( 'members' ) part in, and without that, it seems the search functionality on the directory no longer works. I tried connecting both together with a "." before the array, but it just goes back to displaying all members. Thoughts? – Alyssa Jun 24 '17 at 14:07
0

Solved if anyone needs this:

<?php
// The Query
$user_query = new WP_User_Query( array('has_published_posts' => array('post_type'=>'post')) );

// User Loop
$published_users = array();

if ( ! empty( $user_query->results ) ) {
 foreach ( $user_query->results as $user ) {
    $published_users[] = $user->ID ;

}
} else {
}

$usersimploded = implode(",",$published_users);



if ( bp_ajax_querystring( 'members' ) =="") {
$queryString = 'type=alphabetical&action=alphabetical&include='. $usersimploded .'&page=1&exclude='.'1,2,62';
} else {
$queryString = bp_ajax_querystring( 'members' );
}
?>


<?php if ( bp_has_members( $queryString) ) : ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.