WP PLUGIN バグ修正(カスタムフィールドの値がない場合)
・配列の初期化書式を書き換え ・ソートのカスタムフィールドを4つに変更 ・ソートのJSでカスタムフィールドをdisabledにしないよう変更
This commit is contained in:
+21
-37
@@ -88,39 +88,21 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
|
||||
$query->set( 'posts_per_page', $per_page_option_data );
|
||||
}
|
||||
|
||||
private function set_custom_filed_orderby( $query, $apop_order_param ) {
|
||||
$sort_param = array( 1 => 'ASC', 2 => 'DESC' );
|
||||
if ( ! $apop_order_param ) {
|
||||
return;
|
||||
}
|
||||
foreach ( $apop_order_param as $order_col => $orders ) {
|
||||
if ( $orders['use'] == 1 ) {
|
||||
if ( $order_col == 'custom_field' ) {
|
||||
$sort_meta_key = self::set_custom_filed_sort( $orderby, $order_col, $orders, $sort_param );
|
||||
|
||||
} else {
|
||||
$orderby[ $order_col ] = $sort_param[ $orders['sort'] ];
|
||||
}
|
||||
private static function set_custom_filed_sort( &$orderby, $order_col, $orders, $sort_param ): array {
|
||||
if ( strpos( $order_col, 'custom_field' ) !== false ) {
|
||||
$meta_key = $orders['field']['meta_key'];
|
||||
$orderby_sort = $orders['sort'];
|
||||
$type = 'CHAR';
|
||||
if ( $orders['field']['value_type'] == 'meta_value_num' ) {
|
||||
$type = 'NUMERIC';
|
||||
} elseif ( $orders['field']['value_type'] == 'meta_value' ) {
|
||||
$type = 'CHAR';
|
||||
} elseif ( $orders['field']['value_type'] == 'meta_date' ) {
|
||||
$type = 'DATE';
|
||||
}
|
||||
}
|
||||
$orderby[ $meta_key ] = $sort_param[ $orderby_sort ];
|
||||
|
||||
if ( isset( $sort_meta_key ) ) {
|
||||
$query->set( 'meta_query', self::get_all_post_args( $sort_meta_key ) );
|
||||
}
|
||||
|
||||
if ( isset( $orderby ) ) {
|
||||
$query->set( 'orderby', $orderby );
|
||||
}
|
||||
}
|
||||
|
||||
private static function set_custom_filed_sort( &$orderby, $order_col, $orders, $sort_param ) {
|
||||
if ( $order_col == 'custom_field' ) {
|
||||
$meta_key = $orders['field']['meta_key'];
|
||||
$orderby_key = $orders['field']['value_type'];
|
||||
$orderby_sort = $orders['sort'];
|
||||
$orderby[ $orderby_key ] = $sort_param[ $orderby_sort ];
|
||||
|
||||
return $meta_key;
|
||||
return array( $meta_key, $type );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +114,7 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
|
||||
$this->set_search_normal_orderby( $query, 'normal' );
|
||||
} else {
|
||||
$query->set( 'meta_query', self::get_all_post_args( $sort_meta_key ) );
|
||||
$query->set( 'orderby', array( 'meta_value_num' => 'ASC' ) );
|
||||
$query->set( 'orderby', array( 'meta_value' => 'ASC', ) );
|
||||
}
|
||||
} else {
|
||||
$meta_orderby = self::set_tax_custom_field_orderby( $id );
|
||||
@@ -177,16 +159,18 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
|
||||
return $target;
|
||||
}
|
||||
|
||||
private static function get_all_post_args( $sort_meta_key ): array {
|
||||
private static function get_all_post_args( $sort_meta_key, $type = 'numeric' ): array {
|
||||
return array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
'key' => $sort_meta_key,
|
||||
'compare' => 'EXISTS',
|
||||
'type' => $type,
|
||||
),
|
||||
array(
|
||||
'key' => $sort_meta_key,
|
||||
'compare' => 'NOT EXISTS',
|
||||
'type' => $type,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -196,13 +180,13 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
|
||||
return array();
|
||||
}
|
||||
$sort_param = array( 1 => 'ASC', 2 => 'DESC' );
|
||||
$meta_query = null;
|
||||
$meta_query = array( 'relation' => 'AND' );
|
||||
$orderby = null;
|
||||
foreach ( $apop_order_param as $order_col => $orders ) {
|
||||
if ( $orders['use'] == 1 ) {
|
||||
if ( $order_col == 'custom_field' ) {
|
||||
$sort_meta_key = self::set_custom_filed_sort( $orderby, $order_col, $orders, $sort_param );
|
||||
$meta_query = self::get_all_post_args( $sort_meta_key );
|
||||
if ( strpos( $order_col, 'custom_field' ) !== false ) {
|
||||
list( $sort_meta_key, $type ) = self::set_custom_filed_sort( $orderby, $order_col, $orders, $sort_param );
|
||||
$meta_query[] = self::get_all_post_args( $sort_meta_key, $type );
|
||||
} else {
|
||||
$orderby[ $order_col ] = $sort_param[ $orders['sort'] ];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user