• Andrea, I have created a dating site through sweetdate theme that uses budypress and bpprofile search. I have inserted a php code that filters the members directory default loop to show the opposite sex. I want to filter the search results for the BP Profile Search plugin to only show the opposite sex profiles too. Is this possible? If so, will you advise me on what/how to do this or what code to add to do this?

    Than you in advance for your help!!

    • This topic was modified 6 years, 1 month ago by shaundrania.
    • This topic was modified 6 years, 1 month ago by shaundrania.
Viewing 15 replies - 1 through 15 (of 15 total)
  • Hi there, Are you using the BP Members, Recently Active Members, and Who’s Online widgets?, and did you manage these to show the opposite sex only, by inserting this code in the loop?

    Regards
    Carsten

    Thread Starter shaundrania

    (@shaundrania)

    Hey @carsen-lund,
    Yes I have bpmembers, recently active members drop down on the members page from their profile. I had someone insert the code in the loop of the members page and it worked but it doesn’t work with the BP Profile search. Do you have any suggestions?

    Hi, yes, I got the code from Andrea, and it works very well. I am on my phone right now, but if you look through the topics started by me, about the same subject, you will find the code.

    If you do not find it, I will post it to you, later today.

    Can you help me with the code you got for only showing the opposite sex in the widgets?

    Regards
    Carsten

    Thread Starter shaundrania

    (@shaundrania)

    @carsen-lund, here is the code but now I’m not ABSOLUTELY sure that it prevented the recently active, who’s online widgets. I had the guy remove the “all members” from the profile section. I may have a code for that too but give me a sec to look for it.

    // Show only male or female to opposite sex

    class BP_Custom_User_Ids {

    private $custom_ids = array();

    public function __construct() {

    $this->custom_ids = $this->get_custom_ids();

    add_action( ‘bp_pre_user_query_construct’, array( $this, ‘custom_members_query’ ), 1, 1 );
    add_filter( ‘bp_get_total_member_count’, array( $this, ‘custom_members_count’ ), 1, 1 );

    }

    private function get_custom_ids() {
    global $wpdb;

    //figure out if the logged-in user is male or female
    $sex = xprofile_get_field_data( 303, bp_loggedin_user_id() );

    if ( $sex == ‘Man’ )
    $query = “SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 303 AND value = ‘Woman'”;
    else
    $query = “SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 303 AND value = ‘Man'”;

    $custom_ids = $wpdb->get_col( $query );

    return $custom_ids;
    }

    function custom_members_query( $query_array ) {

    $query_array->query_vars[‘include’] = $this->custom_ids;

    }

    function custom_members_count ( $count ) {

    $new_count = count( $this->custom_ids );
    return $new_count;

    }
    }

    function custom_user_ids( ) {

    new BP_Custom_User_Ids ();

    }

    add_action( ‘bp_before_directory_members’, ‘custom_user_ids’ );

    He also did this to test it out – created four users for testing, they were: FemaleOne, FemaleTwo, MaleOne and MaleTwo and assigned their gender via the back-end. He added a plugin called User Switching which allowed him to switch to these users so they’re marked as previously being logged in (this allows them to be shown on the front-end). Then he disabled the plugin but left it installed for me to use.

    I hope this helps- I’m wondering if it’s the code you used previously.

    Did you have to add it your code to a bp-custom.php file?

    Thread Starter shaundrania

    (@shaundrania)

    @carsten-lund, the other code for removing “all members tab” is li#members-all {display: none;}

    Question- As you your code, are you able to use the matching with these additional conditions added to the site? If so, did you turn off mandatory complimentary matching and complimentary matching? Also, do you use the “I am a” in the profile search without using the “looking for a” question? If doing something different, please share?

    Thanks for your help Carsten. I hope the codes work for you.

    • This reply was modified 6 years, 1 month ago by shaundrania.

    Hi there, Thanks for the code, I will test it one of these days.

    Here is the code snippet I am using, which I got from Andrea. This code actually also work with the Members page, only displaying the opposite sex, but does not influence the BP widgets. Just put it into bp-custom.php file:

    add_filter (‘bp_ajax_querystring’, ‘modify_members_loop’, 20, 2);
    function modify_members_loop ($qs=false, $object=false)
    {
    global $wpdb;
    if ($object != ‘members’) return $qs;

    // figure out if the logged-in user is male or female
    $gender = xprofile_get_field_data (5, bp_loggedin_user_id ());

    if ($gender == ‘Male’)
    $query = “SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 5 AND value = ‘Female'”;
    else
    $query = “SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 5 AND value = ‘Male'”;

    $custom_ids = $wpdb->get_col ($query);

    $args = wp_parse_args ($qs);
    $args[‘include’] = implode (‘,’, $custom_ids);
    $qs = build_query ($args);

    return $qs;
    }

    Replace 5 with the field ID of your ‘Gender’ field.

    To your other questions:

    “As you your code, are you able to use the matching with these additional conditions added to the site?”

    Yes to this, but I am not sure I understand this: “If so, did you turn off mandatory complimentary matching and complimentary matching?”

    I am not using “I am a” “looking for a” in the profile search. This is a choice I made. The users can search for the opposite sex only.

    Regards
    Carsten

    Thread Starter shaundrania

    (@shaundrania)

    @carsten-lund, Ok great! Will do. So, basically with this code we don’t need to use the “I am a” or “looking for” question in the profile search.. only when they initially signup? That’s great! I was hoping I didn’t.

    • This reply was modified 6 years, 1 month ago by shaundrania.

    No, with this code, you do not have the option of searching other profiles of the same sex, even when searching for specific names they do not appear in the search results.

    Of course this can be a draw back, If you want to enable profiles search for other members of their own sex.

    Thread Starter shaundrania

    (@shaundrania)

    Oh, this is great! Beautiful! Will insert this code today. I noticed one other question you had in the forum regarding adding tabs. Did that code workout for you? I think I’m going to add it to mine.

    As for the question that was unclear “making complimentary matching”, I believe that’s specific to my theme-sweetdate. So it probably doesn’t apply to your theme.

    Thank you so much for your help Carsten!

    You are welcome, yes, the code for adding an extra tap worked out for me.

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hello @shaundrania,

    I’m glad you got helpful answers even before I saw your post. And many thanks to @carsten-lund for providing those answers!

    Thread Starter shaundrania

    (@shaundrania)

    Thank you @dontdream!

    The code worked but can you share if there is a code to insert to create an advanced search form on the members page of the members profile? Or maybe add an additional sub-tab called search or advance search that hosts the advance search form (next to members and home tabs) on the profile page?

    I hope that makes sense… 🙂

    Thread Starter shaundrania

    (@shaundrania)

    @dontdream, I just discovered this code but I have a question-
    If I added this members-loop.php for creating an advanced search for members, will it interfere with the gender filter php code I just entered in my site?

    <?php if ( bp_has_members( bp_ajax_querystring( ‘members’ ) ) ) : ?>

    <div id=”pag-top” class=”pagination”>

    <div class=”pag-count” id=”member-dir-count-top”>

    <?php bp_members_pagination_count(); ?>

    </div>

    <div class=”pagination-links” id=”member-dir-pag-top”>

    <?php bp_members_pagination_links(); ?>

    </div>

    </div>

    <?php do_action( ‘bp_before_directory_members_list’ ); ?>

    <ul id=”members-list” class=”item-list” role=”main”>

    <?php while ( bp_members() ) : bp_the_member(); ?>

    • <div class=”item-avatar”>
      “><?php bp_member_avatar(); ?>
      </div>

      <div class=”item”>
      <div class=”item-title”>
      “><?php bp_member_name(); ?>

      <?php if ( bp_get_member_latest_update() ) : ?>

      <span class=”update”> <?php bp_member_latest_update(); ?></span>

      <?php endif; ?>

      </div>

      <div class=”item-meta”><span class=”activity”><?php bp_member_last_active(); ?></span></div>

      <?php do_action( ‘bp_directory_members_item’ ); ?>

      <?php
      /***
      * If you want to show specific profile fields here you can,
      * but it’ll add an extra query for each member in the loop
      * (only one regardless of the number of fields you show):
      *
      * bp_member_profile_data( ‘field=the field name’ );
      */
      ?>
      </div>

      <div class=”action”>

      <?php do_action( ‘bp_directory_members_actions’ ); ?>

      </div>

      <div class=”clear”></div>

    • <?php endwhile; ?>

      <?php do_action( ‘bp_after_directory_members_list’ ); ?>

      <?php bp_member_hidden_fields(); ?>

      <div id=”pag-bottom” class=”pagination”>

      <div class=”pag-count” id=”member-dir-count-bottom”>

      <?php bp_members_pagination_count(); ?>

      </div>

      <div class=”pagination-links” id=”member-dir-pag-bottom”>

      <?php bp_members_pagination_links(); ?>

      </div>

      </div>

      <?php else: ?>

      <div id=”message” class=”info”>
      <p><?php _e( “Sorry, no members were found.”, ‘buddypress’ ); ?></p>
      </div>

      <?php endif; ?>

    Thread Starter shaundrania

    (@shaundrania)

    @carsten-lund and @dontdream, question- did the members page on your site stop showing profiles after adding both or either of the codes discussed here for gender filter? Reason I ask is on the front end of my site the members aren’t showing on the members page, I’m wondering if it’s the code or something I did.

    Thank you!!

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Create search Filter’ is closed to new replies.