要实现BuddyBoss成员目录搜索功能的选项,可以使用以下代码示例:
/**
* 添加成员目录搜索功能的选项
*/
function add_member_directory_search_options() {
// 获取搜索选项的当前值
$current_option = isset( $_GET['search_option'] ) ? sanitize_text_field( $_GET['search_option'] ) : 'recent';
// 输出搜索选项的HTML
echo '
';
}
add_action( 'bp_before_directory_members_content', 'add_member_directory_search_options' );
/**
* 更新成员目录搜索的查询参数
*
* @param array $args 原始查询参数
* @return array 更新后的查询参数
*/
function update_member_directory_search_query( $args ) {
// 获取搜索选项的值
$search_option = isset( $_GET['search_option'] ) ? sanitize_text_field( $_GET['search_option'] ) : 'recent';
// 根据搜索选项更新查询参数
switch ( $search_option ) {
case 'newest':
$args['type'] = 'newest';
break;
case 'alphabetical':
$args['type'] = 'alphabetical';
break;
default:
$args['type'] = 'active';
break;
}
return $args;
}
add_filter( 'bp_after_has_members_parse_args', 'update_member_directory_search_query' );
以上代码将在BuddyBoss成员目录页面添加了一个搜索选项,包括“最近”、“最新”和“字母顺序”。在搜索选项中选择不同的值后,将根据选项更新成员目录的查询参数。可以根据需要将代码添加到主题的functions.php
文件中。