0

I have a list of favorited user ids in PHP. I want to create a secondary membersloop within Buddyboss under a new permalink, e.g.

mypage.com/members/favorited

which only shows the given list of user ids.

The inclusion of only the specific favorited user-ids, I have already implemented as a filter to the membersloop, like so:

function membersloop_show_favorites( $querystring = false, $object = false ) {

    // Only do this for the members loop.
    if ($object != 'members')
        return $querystring;

    // Test Input, comes from database later on ...
    $ids = array(89, 113); // 

    // Make the array a comma sep list.
    $ids = implode( ',', $ids );
    $args = wp_parse_args($querystring);

    if ( ! empty($args['include']) )
        $args['include'] = $args['include'] . ',' . $ids;
    else
        $args['include'] = $ids;

    $querystring = build_query( $args );
    return $querystring;
}
add_action( 'bp_ajax_querystring', 'membersloop_show_favorites', 20, 2 );

The only question is how to make a permalink for that customized membersloop.

tim
  • 9,896
  • 20
  • 81
  • 137
  • 1
    Rather than filter the querystring, why not create a custom members loop as a shortcode and then put the shortcode on a new page? – shanebp Jan 31 '23 at 22:28
  • @shanebp Very good idea but how to "duplicate" the memberloop? Do I have to copy the full membersloop php template and call it via the `bp_get_template_part` or how to do it? – tim Feb 04 '23 at 07:57
  • 1
    Easiest way is to copy, into the shortcode function, the parts you need / want from the `members-loop.php` template, it's not that big. – shanebp Feb 04 '23 at 18:04

0 Answers0