Tagged: filter groups
Hello Brajesh,
I made group fields like here https://pastebin.com/1xXw9rd9, and made types of groups.
I need help,
how can you sort or filter by city and by group type (frontend – html select-city | select-type of group)Hi Vlad,
You may want to look into ‘bp_groups_get_orderby’ filter.Regards
BrajeshHello Brajesh,
did so,
it is working,
the page reloads,
filter bp_groups_directory_order_options stopped working,
what do you recommend on the filter‘
<?phpglobal $wpdb, $bp;
?>
<div>
<form action=”” method=”get”><select name=”groups_search_city” id=”groups_search_city”>
<option value=””>City</option>
<?php$cities = $wpdb->get_col(“SELECT DISTINCT meta_value FROM wp_bp_groups_groupmeta WHERE meta_key = ‘group_custom_field_city'”);
foreach ( $cities as $city ) {
echo ‘<option value=”‘ . $city . ‘”>’ . $city . ‘</option>’;
}
?>
</select><select name=”groups_search_working” id=”groups_search_working”>
<option value=””>Working</option><?php
$workings = $wpdb->get_col(“SELECT DISTINCT meta_value FROM wp_bp_groups_groupmeta WHERE meta_key = ‘group_custom_field_working'”);
foreach ( $workings as $working ) {
echo ‘<option value=”‘ . $working . ‘”>’ . $working . ‘</option>’;
}
?>
</select><?php
$args_meta = array(
‘post-type’ => ‘groups’,
‘per_page’ => ’24’,‘meta_query’ => array(
‘relation’ => ‘AND’,‘group_custom_field_city’ => array(
‘key’ => ‘group_custom_field_city’,
‘value’ => $_POST[‘groups_search_city’],
‘compare’ => ‘LIKE’,
),‘group_custom_field_working’ => array(
‘key’ => ‘group_custom_field_working’,
‘value’ => $_POST[‘groups_search_working’],
‘compare’ => ‘LIKE’,
),
),‘orderby’ => array(
‘group_custom_field_city’ => ‘ASC’,
‘group_custom_field_working’ => ‘ASC’,
)
);?>
<input type=”submit” value=”Search” />
</form>
</div><?php if ( bp_has_groups( $args_meta, ( bp_ajax_querystring( ‘groups’ )) . ‘&per_page=’ . svq_option( ‘bp_groups_perpage’, 24 ) ) ) : ?>
‘Hi Vlad,
I am sorry, The above code will not work.Group is not a post type.
can you please share your code on pastebin and link me? I may be able to have abetter understanding and may be able to assist you.
Regards
BrajeshHi Brajesh,
i didn’t work with pastebin,
here is the code working,
the page is reloading,
works faster than ajax,
will you advise how to do it better,
this is how i did – https://photos.app.goo.gl/5zt7vSC4r3vkAjbZ7
‘
<?php
global $wpdb, $bp;
?>
<div>
<form action=”” method=”get” name=”form_filter” id=”form_filter”>
<select name=”groups_search_city” id=”groups_search_city” class=”livesearch”>
<option value=””>Выбрать город</option><?php
$cities = $wpdb->get_col(“SELECT DISTINCT meta_value FROM wp_bp_groups_groupmeta WHERE meta_key = ‘group_custom_field_city'”);
foreach ( $cities as $city ) {
echo ‘<option value=”‘ . $city . ‘”>’ . $city . ‘</option>’;
}
?>
</select><select name=”groups_search_working” id=”groups_search_working” class=”livesearch”>
<option value=””>Выбрать вид деятельности</option><?php
$workings = $wpdb->get_col(“SELECT DISTINCT meta_value FROM wp_bp_groups_groupmeta WHERE meta_key = ‘group_custom_field_working'”);
foreach ( $workings as $working ) {
echo ‘<option value=”‘ . $working . ‘”>’ . $working . ‘</option>’;
}
?>
</select>
<select name=”groups-order-by” id=”groups-order-by” class=”livesearch”>
<option value=”active”><?php esc_html_e( ‘Last Active’, ‘buddypress’ ); ?></option>
<option value=”popular”><?php esc_html_e( ‘Most Members’, ‘buddypress’ ); ?></option>
<option value=”newest”><?php esc_html_e( ‘Newly Created’, ‘buddypress’ ); ?></option>
<option value=”alphabetical”><?php esc_html_e( ‘Alphabetical’, ‘buddypress’ ); ?></option>
</select>
<?php
$args_meta = array(
‘type’ => $_POST[‘groups-order-by’],
‘per_page’ => ’12’,
‘meta_query’ => array(
‘relation’ => ‘AND’,
‘group_custom_field_city’ => array(
‘key’ => ‘group_custom_field_city’,
‘value’ => $_POST[‘groups_search_city’],
‘compare’ => ‘LIKE’,
),‘group_custom_field_working’ => array(
‘key’ => ‘group_custom_field_working’,
‘value’ => $_POST[‘groups_search_working’],
‘compare’ => ‘LIKE’,
),
),‘orderby’ => array(
‘group_custom_field_city’ => ‘ASC’,
‘group_custom_field_working’ => ‘ASC’,
)
);
?>
<input type=”submit” value=”search” /> reset
</form>
</div><?php if ( bp_has_groups( $args_meta )) : ?>
‘Hi Vlad ,
I am sorry, I am unable to assist you with the above code.It will need the time which is beyond our scope of free community support.
Regards
Brajehs
You must be logged in to reply to this topic.