mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
- add default sorting
This commit is contained in:
@@ -389,6 +389,12 @@ if ( ! class_exists( 'um\admin\Admin' ) ) {
|
||||
'_um_sortby_custom_label' => array(
|
||||
'sanitize' => 'text',
|
||||
),
|
||||
'_um_sortby_custom_type' => array(
|
||||
'sanitize' => 'text',
|
||||
),
|
||||
'_um_sortby_custom_order' => array(
|
||||
'sanitize' => 'text',
|
||||
),
|
||||
'_um_enable_sorting' => array(
|
||||
'sanitize' => 'bool',
|
||||
),
|
||||
|
||||
@@ -7,6 +7,18 @@ global $post_id;
|
||||
$_um_sorting_fields = get_post_meta( $post_id, '_um_sorting_fields', true );
|
||||
$_um_sorting_fields = empty( $_um_sorting_fields ) ? array() : $_um_sorting_fields;
|
||||
|
||||
$custom_type_options = array(
|
||||
'CHAR' => 'CHAR',
|
||||
'NUMERIC' => 'NUMERIC',
|
||||
'BINARY' => 'BINARY',
|
||||
'DATE' => 'DATE',
|
||||
'DATETIME' => 'DATETIME',
|
||||
'DECIMAL' => 'DECIMAL',
|
||||
'SIGNED' => 'SIGNED',
|
||||
'TIME' => 'TIME',
|
||||
'UNSIGNED' => 'UNSIGNED',
|
||||
);
|
||||
|
||||
$fields = array(
|
||||
array(
|
||||
'id' => '_um_sortby',
|
||||
@@ -24,6 +36,27 @@ $fields = array(
|
||||
'value' => UM()->query()->get_meta_value( '_um_sortby_custom', null, 'na' ),
|
||||
'conditional' => array( '_um_sortby', '=', 'other' ),
|
||||
),
|
||||
array(
|
||||
'id' => '_um_sortby_custom_type',
|
||||
'type' => 'select',
|
||||
'label' => __( 'Data type', 'ultimate-member' ),
|
||||
'tooltip' => __( 'To correct sort by a custom field, choose a data type', 'ultimate-member' ),
|
||||
'value' => UM()->query()->get_meta_value( '_um_sortby_custom_type', null, 'CHAR' ),
|
||||
'options' => $custom_type_options,
|
||||
'conditional' => array( '_um_sortby', '=', 'other' ),
|
||||
),
|
||||
array(
|
||||
'id' => '_um_sortby_custom_order',
|
||||
'type' => 'select',
|
||||
'label' => __( 'Order', 'ultimate-member' ),
|
||||
'tooltip' => __( 'To correct sort by a custom field, choose an order', 'ultimate-member' ),
|
||||
'value' => UM()->query()->get_meta_value( '_um_sortby_custom_order', null, 'ASC' ),
|
||||
'options' => array(
|
||||
'ASC' => 'ASC',
|
||||
'DESC' => 'DESC',
|
||||
),
|
||||
'conditional' => array( '_um_sortby', '=', 'other' ),
|
||||
),
|
||||
array(
|
||||
'id' => '_um_sortby_custom_label',
|
||||
'type' => 'text',
|
||||
|
||||
@@ -388,6 +388,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
}
|
||||
update_post_meta( $directory_id, '_um_sortby_custom', '' );
|
||||
update_post_meta( $directory_id, '_um_sortby_custom_label', '' );
|
||||
update_post_meta( $directory_id, '_um_sortby_custom_type', '' );
|
||||
update_post_meta( $directory_id, '_um_sortby_custom_order', '' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1423,7 +1423,8 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
|
||||
|
||||
} elseif ( ( ! empty( $directory_data['sortby_custom'] ) && $sortby == $directory_data['sortby_custom'] ) || in_array( $sortby, $custom_sort ) ) {
|
||||
|
||||
$custom_sort_type = apply_filters( 'um_member_directory_custom_sorting_type', 'CHAR', $sortby, $directory_data );
|
||||
$custom_sort_type = ! empty( $directory_data['sortby_custom_type'] ) ? $directory_data['sortby_custom_type'] : 'CHAR';
|
||||
$custom_sort_type = apply_filters( 'um_member_directory_custom_sorting_type', $custom_sort_type, $sortby, $directory_data );
|
||||
|
||||
$this->query_args['meta_query'][] = array(
|
||||
'relation' => 'OR',
|
||||
@@ -1438,7 +1439,9 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
|
||||
)
|
||||
);
|
||||
|
||||
$this->query_args['orderby'] = array( $sortby . '_cs' => 'ASC', 'user_login' => 'ASC' );
|
||||
$custom_sort_order = ! empty( $directory_data['sortby_custom_order'] ) ? $directory_data['sortby_custom_order'] : 'CHAR';
|
||||
|
||||
$this->query_args['orderby'] = array( $sortby . '_cs' => $custom_sort_order, 'user_login' => 'ASC' );
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user