Forums › Kleo Geolocation › Geo Location Not Working as Intended with Custom Members Loop on a Page Template
Tagged: custom members loop, Kleo Geolocation, members loop
- This topic has 1 reply, 1 voice, and was last updated 6 years, 4 months ago by
Mark Behnken.
-
AuthorPosts
-
February 6, 2016 at 11:04 am #50552
Mark Behnken
MemberHi Eyal,
I am using the Kleo theme and your Kleo Geolocation add-on. Using the code snippets below via instructions from the BP Codex, I have successfully configured the default members loop (members page) to only show female members who are currently online. Now when searching using a geo search, all works as intended as it only shows “female members” “online” within the radius of the location I entered in the search box.
However, I cannot get this to work correctly when using a custom members loop on a page set up via a custom template. Geo searches work correctly, however, it does not show only online female members but instead returns all members (male and female, online or offline) when performing a Geo search. Do you have any insight into why this works fine on the default members loop (members page) but not on a page using a custom template?
I’ve provided all the code I am using below for your reference. I’ve also attached my functions.php and page template to this ticket since it doesn’t appear to be displaying correctly on the page.
Code added to my custom page template file to only return female members who are online:
1234$user_ids = my_custom_ids( 'gender', 'female' );if ( bp_has_members( array('type' => 'online','include' => $user_ids ) ) ) :Code added to my functions.php to allow the above code to work so I can display online female members only:
1234567891011121314151617181920212223242526272829303132function my_custom_ids( $field_name, $field_value = '' ) {if ( empty( $field_name ) )return '';global $wpdb;$field_id = xprofile_get_field_id_from_name( $field_name );if ( !empty( $field_id ) )$query = "SELECT user_id FROM " . $wpdb->prefix . "bp_xprofile_data WHERE field_id = " . $field_id;elsereturn '';if ( $field_value != '' )$query .= " AND value = '" . $field_value . "'";/*LIKE is slow. If you're sure the value has not been serialized, you can do this:$query .= " AND value = '" . $field_value . "'";*/$custom_ids = $wpdb->get_col( $query );if ( !empty( $custom_ids ) ) {// convert the array to a csv string$custom_ids_str = implode(",", $custom_ids);return $custom_ids_str;}elsereturn '';}My Custom Page Template Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125/*** Template Name: test** Description: test** @package WordPress* @subpackage Kleo* @author SeventhQueen <themesupport@seventhqueen.com>* @since Kleo 1.0*/get_header() ?><?php//create right sidebar templatekleo_switch_layout('right');?><?php get_template_part('page-parts/general-title-section'); ?><?php get_template_part('page-parts/general-before-wrap'); ?><?php$user_ids = my_custom_ids( 'gender', 'female' );if ( bp_has_members( array('type' => 'online','include' => $user_ids ) ) ) : ?><?php echo do_shortcode('[gmw form="2"]'); ?><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 row kleo-isotope masonry"><?php while ( bp_members() ) : bp_the_member(); ?><li class="kleo-masonry-item"><div class="member-inner-list animated animate-when-almost-visible bottom-to-top"><div class="item-avatar rounded"><a href="<?php bp_member_permalink(); ? rel="nofollow">"><?php bp_member_avatar('type=full&width=140px&height=140px'); ?></a><?php do_action('bp_member_online_status', bp_get_member_user_id()); ?></div><div class="item"><div class="item-title"><a href="<?php bp_member_permalink(); ? rel="nofollow">"><?php bp_member_name(); ?></a></div><span class="update"><?php echo_age(bp_get_member_profile_data('field=Age')); ?> | <?php bp_member_profile_data( 'field=Location' ); ?> </span><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"></div></div><!--end member-inner-list--></li><?php endwhile; ?></ul><?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; ?><?php do_action( 'bp_after_members_loop' ); ?><?php get_template_part('page-parts/general-after-wrap'); ?><?php get_footer(); ?>Thank you for your help!
Regards,
MarkFebruary 6, 2016 at 11:15 am #50553Mark Behnken
MemberReattaching files renamed to .txt, .php did not upload.
Attachments:
You must be logged in to view attached files. -
AuthorPosts
You must be logged in to reply to this topic.