Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

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

  • panosa1973
    Participant

    @panosa1973

    Thank you @vapvarun. I googled what you suggested and found https://geomywp.com/. I sent them an email. Hopefully they have something for what I’m looking for.
    Thanks for the input.
    -Panos


    panosa1973
    Participant

    @panosa1973

    Does anyone know how to fix this? I can’t launch my site if I don’t resolve this and I’ve spent hundreds of ours on this project. The alternative would be to completely remove the sorting option but that’s not even an option really. The members should be able to re-sort the results of a custom directory and get back the same results instead of the results of the default directory.
    Any help would be greatly appreciated.
    Thank you.


    panosa1973
    Participant

    @panosa1973

    Ok but shouldn’t the sorting of a custom directory sort the content of the same custom directory instead of the content of another directory? I modified my default directory to only show certain members and sorting that works fine. But it seems that when I sort my custom directory it reverts back to my default. Is there a way to fix that? Is there a hook or something? It just doesn’t make sense that sorting a directory resets all the filters.

    Thanks


    panosa1973
    Participant

    @panosa1973

    Is this a bug? I’ve been trying to figure this out for days. Why does my custom member directory revert to the default when I sort it??? I load it, it works fine and outputs the filtered users. I sort it by Alphabetical order (for example) and it gives me all users again. Does anyone have an idea why this is happening?

    [members-loop-2.php]

    <?php
    /**
     * BuddyPress - Members Loop
     *
     * Querystring is set via AJAX in _inc/ajax.php - bp_legacy_theme_object_filter()
     *
     * @package BuddyPress
     * @subpackage bp-legacy
     */
    
    /**
     * Fires before the display of the members loop.
     *
     * @since 1.2.0
     */
    do_action( 'bp_before_members_loop' ); ?>
    
    <?php if ( bp_get_current_member_type() ) : ?>
    	<p class="current-member-type"><?php bp_current_member_type_message() ?></p>
    <?php endif; ?>
    
    <?php if ( bp_has_members( bp_ajax_querystring( 'members' ) .'&include=' .get_user_matches()  ) ) : ?>
    
    	<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
    
    	/**
    	 * Fires before the display of the members list.
    	 *
    	 * @since 1.1.0
    	 */
    	do_action( 'bp_before_directory_members_list' ); ?>
    
    	<ul id="members-list" class="item-list" aria-live="assertive" aria-relevant="all">
    
    	<?php while ( bp_members() ) : bp_the_member(); ?>
    		<li <?php bp_member_class(); ?>>
            
    			<div class="item-avatar">
    				<a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
    			</div>
    
    			<div class="item">
    				<div class="item-title">
    					<a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a>
    
    					<?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" data-livestamp="<?php bp_core_iso8601_date( bp_get_member_last_active( array( 'relative' => false ) ) ); ?>"><?php bp_member_last_active(); ?></span></div>
    
    				<?php
    
    				/**
    				 * Fires inside the display of a directory member item.
    				 *
    				 * @since 1.1.0
    				 */
    				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):
    				  *
    				  * $xGender =  bp_member_profile_data( 'field=Gender' );
    				  */
    				  
    				?>
    			</div>
    
    			<div class="action">
    
    				<?php
    
    				/**
    				 * Fires inside the members action HTML markup to display actions.
    				 *
    				 * @since 1.1.0
    				 */
    				do_action( 'bp_directory_members_actions' ); ?>
    
    			</div>
    
    			<div class="clear"></div>
    		</li>
    	<?php endwhile; ?>
    
    	</ul>
    
    	<?php
    
    	/**
    	 * Fires after the display of the members list.
    	 *
    	 * @since 1.1.0
    	 */
    	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; ?>
    
    <?php
    
    /**
     * Fires after the display of the members loop.
     *
     * @since 1.2.0
     */
    do_action( 'bp_after_members_loop' );

    [index-2.php]
    ‘<?php
    /**
    * BuddyPress – Members
    *
    * @package BuddyPress
    * @subpackage bp-legacy
    */

    /**
    * Fires at the top of the members directory template file.
    *
    * @since 1.5.0
    */
    do_action( ‘bp_before_directory_members_page’ ); ?>

    <div id=”buddypress”>

    <?php

    /**
    * Fires before the display of the members.
    *
    * @since 1.1.0
    */
    do_action( ‘bp_before_directory_members’ ); ?>

    <?php

    /**
    * Fires before the display of the members content.
    *
    * @since 1.1.0
    */
    do_action( ‘bp_before_directory_members_content’ ); ?>

    <?php /* Backward compatibility for inline search form. Use template part instead. */ ?>
    <?php if ( has_filter( ‘bp_directory_members_search_form’ ) ) : ?>

    <div id=”members-dir-search” class=”dir-search” role=”search”>
    <?php bp_directory_members_search_form(); ?>
    </div><!– #members-dir-search –>

    <?php else: ?>

    <?php bp_get_template_part( ‘common/search/dir-search-form’ ); ?>

    <?php endif; ?>

    <?php
    /**
    * Fires before the display of the members list tabs.
    *
    * @since 1.8.0
    */
    do_action( ‘bp_before_directory_members_tabs’ ); ?>

    <form action=”” method=”post” id=”members-directory-form” class=”dir-form”>

    <div class=”item-list-tabs” id=”subnav” aria-label=”<?php esc_attr_e( ‘Members directory secondary navigation’, ‘buddypress’ ); ?>” role=”navigation”>

      <?php

      /**
      * Fires inside the members directory member sub-types.
      *
      * @since 1.5.0
      */
      do_action( ‘bp_members_directory_member_sub_types’ ); ?>

      <li id=”members-order-select” class=”last filter”>
      <label for=”members-order-by”><?php _e( ‘Order By:’, ‘buddypress’ ); ?></label>
      <select id=”members-order-by”>
      <option value=”active”><?php _e( ‘Last Active’, ‘buddypress’ ); ?></option>
      <option value=”newest”><?php _e( ‘Newest Registered’, ‘buddypress’ ); ?></option>

      <?php if ( bp_is_active( ‘xprofile’ ) ) : ?>
      <option value=”alphabetical”><?php _e( ‘Alphabetical’, ‘buddypress’ ); ?></option>
      <?php endif; ?>

      <?php

      /**
      * Fires inside the members directory member order options.
      *
      * @since 1.2.0
      */
      do_action( ‘bp_members_directory_order_options’ ); ?>
      </select>

    </div>

    <h2 class=”bp-screen-reader-text”><?php
    /* translators: accessibility text */
    _e( ‘Members directory’, ‘buddypress’ );
    ?></h2>

    <div id=”members-dir-list” class=”members dir-list”>
    <?php bp_get_template_part( ‘members/members-loop-2’ ); ?>
    </div><!– #members-dir-list –>

    <?php

    /**
    * Fires and displays the members content.
    *
    * @since 1.1.0
    */
    do_action( ‘bp_directory_members_content’ ); ?>

    <?php wp_nonce_field( ‘directory_members’, ‘_wpnonce-member-filter’ ); ?>

    <?php

    /**
    * Fires after the display of the members content.
    *
    * @since 1.1.0
    */
    do_action( ‘bp_after_directory_members_content’ ); ?>

    </form><!– #members-directory-form –>

    <?php

    /**
    * Fires after the display of the members.
    *
    * @since 1.1.0
    */
    do_action( ‘bp_after_directory_members’ ); ?>

    </div><!– #buddypress –>

    <?php

    /**
    * Fires at the bottom of the members directory template file.
    *
    * @since 1.5.0
    */
    do_action( ‘bp_after_directory_members_page’ );


    panosa1973
    Participant

    @panosa1973

    I posted this and I realized I’m pulling a birthday field (1974-03-10 00:00:00), not an age number like 20, but it’s the same principal. If your field is an age number field then just replace $five_years_older = date("Y-m-d H:i:s", strtotime("-5 years", strtotime($my_birthday))); with $five_years_older = $my_birthday + 5; and the use this query instead:
    $my_matches = $wpdb->get_col("SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND value = '$i_am_looking_for' AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 197 AND value = '$my_gender') AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value BETWEEN '$my_birthday' AND '$five_years_older')");
    For the sake of clarity, in this case $my_birthday should be replaced with $my_age. I know, OCD 🙂


    panosa1973
    Participant

    @panosa1973

    Give this a try. I didn’t validate it but it should work. Let me know.
    Field #2 is the birthday field.

    function get_desired_users () {
    		global $wpdb;
    		$my_user_id = bp_loggedin_user_id();
    		$my_gender = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND user_id = $my_user_id");
    		$i_am_looking_for = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 197 AND user_id = $my_user_id");
    	        $my_birthday = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND user_id = $my_user_id");
                    $five_years_older = date("Y-m-d H:i:s", strtotime("-5 years", strtotime($my_birthday)));
    
    		//Get all users that are what the logged_in member is looking for
    		 $my_matches = $wpdb->get_col("SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND value = '$i_am_looking_for' AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 197 AND value = '$my_gender') AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value BETWEEN '$five_years_older' AND '$my_birthday')");
    		 
    		$include = implode(",", $my_matches);
          	        return $include;
    }

    panosa1973
    Participant

    @panosa1973

    @emmanuel1234, I did the exact same thing on my site but I took it a step further. For example, if the user is a man who is looking for a woman, then the directory will only show women who are looking for men, not just all women (some women might be looking for other women etc.).

    Step 1: The below code is in my bp_custom.php where field #193 is the user’s gender and field #197 is the gender the user is looking for. Replace them with your field IDs.

    function get_desired_users () {
    		global $wpdb;
    		$my_user_id = bp_loggedin_user_id();
    		$my_gender = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND user_id = $my_user_id");
    		$i_am_looking_for = $wpdb->get_var("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 197 AND user_id = $my_user_id");
    	
    		//Get all users that are what the logged_in member is looking for
    		 $my_matches = $wpdb->get_col("SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 193 AND value = '$i_am_looking_for' AND user_id IN (SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 197 AND value = '$my_gender')");
    		 
    		$include = implode(",", $my_matches);
          	        return $include;
    }

    Then in your members_loop page, in the bp_ajax_querystring line add the function that returns the user IDs like so:
    <?php if ( bp_has_members( bp_ajax_querystring( 'members' ) .'&include=' .get_desired_users() ) ) : ?>

    That works like a charm for me.


    panosa1973
    Participant

    @panosa1973

    I’m realizing I might nor be clear. I want to leave the value of the option as is and just convert the part that’s showing up in the drop-down menu.
    Thanks.


    panosa1973
    Participant

    @panosa1973

    Thanks @shanebp. I figured out what was going on. $my_matches = array($wpdb->get_col ... was producing a two-dimensional array, that’s why $my_matches[0] was not returning a value. The $user_ids ware actually being stored in $my_matches[0][0] ($my_matches[0][1], $my_matches[0][2] and so forth), which is unnecessary. So I changed this, $my_matches = array($wpdb->get_col ... to this, $my_matches = $wpdb->get_col ... and now $my_matches[0] ($my_matches[1], $my_matches[2] etc.) returns the actual $user_id and the pagination works as it should.

    The only thing is that the All Members box still displays the total member count but I don’t really care because I don’t want it there anyway so I hid it with CSS.

    Thank you!
    -Panos


    panosa1973
    Participant

    @panosa1973

    @venutius you were right on the money! This worked. Now a member can see their Friends menu item even when they’re on another member’s profile but without having access to the other member’s friends. And you said it was gonna be difficult. Hah! 🙂
    Thank you yet again!

    function hide_friends_tab() {
    	global $bp;
    	if ( !bp_is_my_profile() && !is_super_admin() ) {
    		bp_core_remove_nav_item( 'friends' ); 
    
    		bp_core_new_nav_item( 
        	        array( 
                    'name' => __('Friends', 'buddypress'), 
                    'slug' =>  $bp->friends->slug, 
                    'position' => 50, 
                    'show_for_displayed_user' => false,
                    'default_subnav_slug' => 'friends'
        ));
    	
    	}
    }
    add_action( 'bp_setup_nav', 'hide_friends_tab', 15 );

    panosa1973
    Participant

    @panosa1973

    Thank you. I’ll give it a try.


    panosa1973
    Participant

    @panosa1973

    Hi @venutius. This works the same as my code. Say I’m a regular member viewing another member’s profile. The issue is that when it detects that it’s not my profile page and it removes the other member’s Friends tab, it also removes my own Friends menu item from my Main Menu. So basically when I’m viewing someone else’s profile, I don’t have the link to my main menu to visit my own Friends page because bp_core_remove_nav_item( 'friends' ); removes that too.


    panosa1973
    Participant

    @panosa1973

    Very true 🙂
    Thanks again.


    panosa1973
    Participant

    @panosa1973

    Yes! bp_get_member_user_id() did the job.
    My working code now is:

    //Add fields in the member directory results
    function add_info_to_members_loop() {
    	global $wpdb; 
    	$dateOfBirth = array();
    	$user_id = bp_get_member_user_id();
    	$dateOfBirth = $wpdb->get_col("SELECT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND user_id = $user_id");
    	$dob =  $dateOfBirth[0];
    
    $today = date("Y-m-d");
    $diff = date_diff(date_create($dob), date_create($today));
    $state = bp_get_member_profile_data( 'field=State' );
    echo 'Age '.$diff->format('%y')  . ' - In ' . $state;
    //This will output i.e.: Age 35 - In New York 
    }
    add_action( 'bp_directory_members_item', 'add_info_to_members_loop' );

    Thank you @venutius!


    panosa1973
    Participant

    @panosa1973

    Ok, tried that too. This one doesn’t return anything either.


    panosa1973
    Participant

    @panosa1973

    It looked like it would do it but bp_displayed_user_id(); returns 0. There must be a way to get the ID of the user who’s inside the current loop.


    panosa1973
    Participant

    @panosa1973

    I managed to hide the View tab with CSS:

    function remove_some_tabs() {
        if ( !is_super_admin()) {
    		//This hides the View tab
    		echo '<style>li#public-personal-li {Display: none;} </style>';
    		//This hides the additional members input box when sending a msg
    		echo '<style>#send-to-input {Display: none;} </style>';        
    	}
    }
    add_action( 'wp_head', 'remove_some_tabs');

    panosa1973
    Participant

    @panosa1973

    Thanks for your reply. I tried your code but it doesn’t do anything. My Friends tab was already removed. I want to remove the View tab. When you say “it will not work for first sub nav like the view” do you mean there’s no way to remove the View tab?
    Thank again.


    panosa1973
    Participant

    @panosa1973

    Probably. I’ll post it here if I figure out.
    Thanks again.


    panosa1973
    Participant

    @panosa1973

    @venutius,
    Yes, you’re right. It took me a while to replace all instances of Friend/s with Connection/s.
    I have to do that though so I’ll keep digging. Not sure why this isn’t working.

    Thanks for your time.


    panosa1973
    Participant

    @panosa1973

    @venutius and @vapvarun,
    Thank you for responding. I followed your advice but still nothing. Where does BuddyPress get the language from? Maybe I can edit the original file and see if that works. If that’s even a possibility.

    Thank you.


    panosa1973
    Participant

    @panosa1973

    I also switched to the default theme but no luck.
    Thanks.

Viewing 22 replies - 1 through 22 (of 22 total)
Skip to toolbar