Reply To: Member Loop only MemberPress members
Hey @shanebp thank you so much for your fast response!
Unfortunately, MemberPress support didn’t know of a function that gets user IDs with specific memberships so they handed me this SQL query:
SELECT DISTINCT user_id FROM wp_mepr_transactions WHERE status IN('confirmed','complete') AND (expires_at >= NOW() OR expires_at = '0000-00-00 00:00:00') AND product_id = 123;
Where I would need to change my Product ID to match the Membership ID. I’m assuming I would just add this SQL query to your code bit:
<?php //get ids of members I want to include by grabbing members from db
$memberPressMembers = $wpdb->get_results("SELECT DISTINCT user_id FROM wp_mepr_transactions WHERE status IN('confirmed','complete') AND (expires_at >= NOW() OR expires_at = '0000-00-00 00:00:00') AND product_id = MEMBERSHIPID");
$include_string = '&include=' . implode(", ", $memberPressMembers); ?>
<?php if ( bp_has_members( bp_ajax_querystring( 'members' ) . $include_string ) ) : ?>
This would only call my database 1 time to grab all members who have those specific IDs.
Is that correct? Am I missing anything? When I attempted this I kept getting a 500 error on my admin_ajax.