WP PLUGIN 投稿表示順設定
・タクソノミーのソート順登録/未登録両方取得するようget_postsのパラメータを修正 ・タクソノミーのソート順登録/未登録両方取得に伴いテンプレートを修正 ・通常と検索のソート順登録/未登録両方取得するようget_postsのパラメータを修正 ・「表示設定に従う」メニューへposts_per_pageの設定件数を表示 ・バグ修正:検索設定のnema属性修正と検索ページのメソッド引数修正
This commit is contained in:
+31
-10
@@ -22,29 +22,27 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
|
||||
}
|
||||
|
||||
if ( is_search() ) {
|
||||
$this->set_search_normal_orderby( $query, 'normal' );
|
||||
$this->set_search_normal_orderby( $query, 'search' );
|
||||
}
|
||||
|
||||
if ( is_category() ) {
|
||||
$cat = get_category_by_slug( $query->query_vars['category_name'] );
|
||||
$this->set_orderby( $query, $cat->term_id, 'category', 'cat' );
|
||||
|
||||
}
|
||||
|
||||
if ( is_tag() ) {
|
||||
$tag = get_term_by( 'slug', $query->query_vars['tag'], 'post_tag' );
|
||||
$this->set_orderby( $query, $tag->term_id, 'post_tag', 'tag' );
|
||||
|
||||
}
|
||||
|
||||
if ( is_tax() ) {
|
||||
$this->set_orderby( $query, get_queried_object_id(), 'tax', 'tax' );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private function set_per_page( $query, $target ) {
|
||||
$per_page_option = get_option( '_apop_per_page' );
|
||||
|
||||
if ( ! isset( $per_page_option[ $target ] ) ) {
|
||||
return;
|
||||
}
|
||||
@@ -61,7 +59,8 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
|
||||
private function set_search_normal_orderby( $query, $type ) {
|
||||
$apop_order = get_option( '_apop_' . $type . '_order' ) ?? 1;
|
||||
if ( $apop_order == 2 ) {
|
||||
$query->set( 'meta_key', '_apop_post_' . $type );
|
||||
//$query->set( 'meta_key', '_apop_post_' . $type );
|
||||
$query->set( 'meta_query', self::get_all_post_args( '_apop_' . $type . '_order' ) );
|
||||
$query->set( 'orderby', array( 'meta_value_num' => 'ASC' ) );
|
||||
} else {
|
||||
$apop_order_param = get_option( '_apop_' . $type . '_order_param' );
|
||||
@@ -87,21 +86,43 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
|
||||
$order_settings = get_option( '_apop_' . $order_key . '_order' );
|
||||
if ( isset( $order_settings['target_cat'][ $id ] ) && $order_settings['target_cat'][ $id ] == 1 ) {
|
||||
$sort_meta_key = '_apop_post_' . $target . '_' . $id;
|
||||
$query->set( 'meta_key', $sort_meta_key );
|
||||
//$query->set( 'meta_key', $sort_meta_key );
|
||||
$query->set( 'meta_query', self::get_all_post_args( $sort_meta_key ) );
|
||||
$query->set( 'orderby', array( 'meta_value_num' => 'ASC' ) );
|
||||
$target = 'post_tag' ? 'tag' : $target;
|
||||
$this->set_per_page( $query, $target );
|
||||
$this->set_per_page( $query, self::get_per_page_tag( $target ) );
|
||||
} else {
|
||||
self::set_search_normal_orderby( $query, 'normal' );
|
||||
}
|
||||
}
|
||||
|
||||
private static function get_per_page_tag( $target ) {
|
||||
if ( $target == 'post_tag' ) {
|
||||
return 'tag';
|
||||
}
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
private static function get_all_post_args( $sort_meta_key ): array {
|
||||
return array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
'key' => $sort_meta_key,
|
||||
'compare' => 'EXISTS',
|
||||
),
|
||||
array(
|
||||
'key' => $sort_meta_key,
|
||||
'compare' => 'NOT EXISTS',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public static function get_normal_orderby() {
|
||||
$apop_order = get_option( '_apop_normal_order' ) ?? 1;
|
||||
if ( $apop_order == 2 ) {
|
||||
return array(
|
||||
'meta_key' => '_apop_post_normal',
|
||||
'orderby' => array( 'meta_value_num' => 'ASC' ),
|
||||
'meta_query' => self::get_all_post_args( '_apop_normal_order' ),
|
||||
'orderby' => array( 'meta_value_num' => 'ASC' ),
|
||||
);
|
||||
} else {
|
||||
$apop_order_param = get_option( '_apop_normal_order_param' );
|
||||
|
||||
Reference in New Issue
Block a user