WP PLUGIN アーカイブページの投稿表示順設定
・タクソノミーの1ページ表示数をタクソノミー毎のなるよう修正 ・タクソノミーの1ページ表示数変更に合わせてJSを修正 ・タクソノミーの1ページ表示数変更に合わせてテンプレートファイル分割 ・バグ修正:タームIDが無い存在しない場合にpre_get_postでセットしないよう修正 ・バグ修正:通常と検索のpre_get_postでメタキー指定が漏れていたので追加 ・バグ修正:カスタムタクソノミーのpre_get_postでメタキー指定が異なっていたので修正
This commit is contained in:
+22
-11
@@ -27,41 +27,52 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
|
||||
|
||||
if ( is_category() ) {
|
||||
$cat = get_category_by_slug( $query->query_vars['category_name'] );
|
||||
$this->set_orderby( $query, $cat->term_id, 'category', 'cat' );
|
||||
if ( isset( $cat->term_id ) ) {
|
||||
$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 ( isset( $tag->term_id ) ) {
|
||||
$this->set_orderby( $query, $tag->term_id, 'post_tag', 'tag' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_tax() ) {
|
||||
$this->set_orderby( $query, get_queried_object_id(), 'tax', 'tax' );
|
||||
if ( get_queried_object_id() ) {
|
||||
$this->set_orderby( $query, get_queried_object_id(), 'tax', 'tax' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function set_per_page( $query, $target ) {
|
||||
private function set_per_page( $query, $target, $id = null ) {
|
||||
$per_page_option = get_option( '_apop_per_page' );
|
||||
if ( is_null( $id ) ) {
|
||||
$per_page_option_data = $per_page_option[ $target ];
|
||||
} else {
|
||||
$per_page_target = $target == 'tax' ? 'taxonomy' : $target;
|
||||
$per_page_option_data = $per_page_option[ $per_page_target ][ $id ];
|
||||
}
|
||||
|
||||
if ( ! isset( $per_page_option[ $target ] ) ) {
|
||||
if ( ! isset( $per_page_option_data ) ) {
|
||||
return;
|
||||
}
|
||||
if ( $per_page_option[ $target ] == 'default' ) {
|
||||
if ( $per_page_option_data == 'default' ) {
|
||||
return;
|
||||
}
|
||||
if ( $per_page_option[ $target ] == 'all' ) {
|
||||
if ( $per_page_option_data == 'all' ) {
|
||||
$target = 'search';
|
||||
}
|
||||
|
||||
$query->set( 'posts_per_page', $per_page_option[ $target ] );
|
||||
$query->set( 'posts_per_page', $per_page_option_data );
|
||||
}
|
||||
|
||||
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_query', self::get_all_post_args( '_apop_' . $type . '_order' ) );
|
||||
$query->set( 'orderby', array( 'meta_value_num' => 'ASC' ) );
|
||||
$query->set( 'meta_query', self::get_all_post_args( '_apop_post_' . $type ) );
|
||||
} else {
|
||||
$apop_order_param = get_option( '_apop_' . $type . '_order_param' );
|
||||
$sort_param = array( 1 => 'ASC', 2 => 'DESC' );
|
||||
@@ -89,7 +100,7 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
|
||||
//$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' ) );
|
||||
$this->set_per_page( $query, self::get_per_page_tag( $target ) );
|
||||
$this->set_per_page( $query, self::get_per_page_tag( $target ), $id );
|
||||
} else {
|
||||
self::set_search_normal_orderby( $query, 'normal' );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user