WP PLUGIN 投稿表示順設定

・タクソノミーのソート順登録/未登録両方取得するようget_postsのパラメータを修正
・タクソノミーのソート順登録/未登録両方取得に伴いテンプレートを修正
・通常と検索のソート順登録/未登録両方取得するようget_postsのパラメータを修正
・「表示設定に従う」メニューへposts_per_pageの設定件数を表示
・バグ修正:検索設定のnema属性修正と検索ページのメソッド引数修正
This commit is contained in:
2021-05-08 11:50:31 +09:00
parent bacd6a1d72
commit df9c7deef1
7 changed files with 334 additions and 326 deletions
+89 -83
View File
@@ -15,24 +15,47 @@ if ( ! class_exists( 'APOP_UI' ) ) {
return $type_data;
}
public static function get_all_search_normal_posts( $type, $key, $exclude_posts = [] ) {
$args = [
public static function get_all_search_normal_posts( $key ): string {
$meta_key = '_apop_post_' . $key;
$args = self::create_search_normal_args( $meta_key );
$posts_data = get_posts( $args );
$list = [];
foreach ( $posts_data as $i => $post_data ) {
$order = $i + 1;
$no_order = self::is_sort_post_registered( $post_data->ID, $meta_key ) ? '' : ' no_order';
$list[] = '<li class="product-list' . $no_order . '">' . self::crate_non_registerd_mark( $no_order ) . '
<span class="sort-num-label">' . $order . '</span>' . $post_data->post_title . '
<input type="hidden" class="list_order" name="_apop_post_' . $key . '[post_sort][' . $post_data->ID . ']" value="' . $order . '">
</li>';
}
return implode( PHP_EOL, $list );
}
private static function crate_non_registerd_mark( $no_order ) {
if ( ! empty( $no_order ) ) {
return '&#9632;';
}
return '';
}
private static function create_search_normal_args( $meta_key ): array {
return array(
'post_status' => array( 'publish', 'draft' ),
'posts_per_page' => - 1,
];
if ( $type == 'registered' ) {
$args['orderby'] = 'meta_value_num';
$args['order'] = 'ASC';
$args['meta_key'] = '_apop_post_' . $key;
} else {
$exclude = implode( ',', $exclude_posts );
if ( ! empty( $exclude ) ) {
$args['exclude'] = $exclude;
}
}
return get_posts( $args );
'meta_query' => array(
'relation' => 'OR',
array(
'key' => $meta_key,
'compare' => 'EXISTS',
),
array(
'key' => $meta_key,
'compare' => 'NOT EXISTS',
),
),
);
}
@@ -98,45 +121,64 @@ if ( ! class_exists( 'APOP_UI' ) ) {
return array();
}
public static function create_order_list( $tax_data, $tax_key, $exclude_posts ): array {
$target_posts = self::get_sort_post_list( $tax_data->term_id, $tax_key, $tax_data->taxonomy );
public static function create_order_list( $tax_data, $tax_key ): string {
$return_data = self::get_sort_post_list( $tax_data->term_id, $tax_key, $tax_data->taxonomy );
$list = [];
$sort_num = 0;
foreach ( $target_posts as $key => $target_post ) {
foreach ( $return_data['data'] as $key => $target_post ) {
$sort_num = $key + 1;
$exclude_posts[] = $target_post->ID;
$no_order = self::is_sort_post_registered( $target_post->ID, $return_data['meta_key'] ) ? '' : ' no_order';
$list[] = '
<li class="product-list"><span class="sort-num-label">' . $sort_num . '</span>' . get_the_title( $target_post->ID ) . '
<li class="product-list' . $no_order . '">' . self::crate_non_registerd_mark( $no_order ) . '<span class="sort-num-label">' . $sort_num . '</span>' . get_the_title( $target_post->ID ) . '
<input type="hidden" class="list_order"
name="_apop_post_' . self::create_post_sort_key( $tax_data->taxonomy, $tax_key ) . '[post_sort][' . $tax_data->term_id . '][' . $target_post->ID . ']"
value="' . $sort_num . '">
</li>';
}
return array(
implode( PHP_EOL, $list ),
$exclude_posts,
$sort_num,
);
return implode( PHP_EOL, $list );
}
private static function get_sort_post_list( $tax_id, $search_param, $tax_name ) {
$args = [
private static function is_sort_post_registered( $id, $key ): bool {
if ( get_post_meta( $id, $key, true ) ) {
return true;
}
return false;
}
private static function get_sort_post_list( $tax_id, $search_param, $tax_name ): array {
$args = array(
'post_status' => array( 'publish', 'draft' ),
'posts_per_page' => - 1,
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_key' => '_apop_post_' . self::create_post_sort_key( $tax_name, $search_param ) . '_' . $tax_id,
];
);
$meta_key = '_apop_post_' . self::create_post_sort_key( $tax_name, $search_param ) . '_' . $tax_id;
self::create_sort_post_list_meta_query( $args, $meta_key );
self::create_post_tax_query( $args, $search_param, $tax_name, $tax_id );
return get_posts( $args );
return array(
'meta_key' => $meta_key,
'data' => get_posts( $args )
);
}
private static function create_post_sort_key( $tax_name, $tax_key ) {
private static function create_sort_post_list_meta_query( &$args, $meta_key ) {
$args['meta_query'] = array(
'relation' => 'OR',
array(
'key' => $meta_key,
'compare' => 'EXISTS',
),
array(
'key' => $meta_key,
'compare' => 'NOT EXISTS',
),
);
}
public static function create_post_sort_key( $tax_name, $tax_key ) {
if ( $tax_key == 'taxonomy' ) {
return 'tax';
}
@@ -159,45 +201,6 @@ value="' . $sort_num . '">
}
}
public static function create_product_none_order_list( $tax_data, $tax_key, $exclude_posts, $sort_num ): string {
$target_posts_no_order = self::get_none_sort_post_list( $tax_data->term_id, $tax_key, $exclude_posts, $tax_data->taxonomy );
if ( count( $target_posts_no_order ) > 0 ) {
$sort_num = $sort_num ?? 0;
foreach ( $target_posts_no_order as $key => $target_post_no_order ) {
$sort_num_no_order = $sort_num + $key + 1;
$list[] = '
<li class="product-list no_order">&#9632;
<span class="sort-num-label">' . $sort_num_no_order . '</span>' . get_the_title( $target_post_no_order->ID ) . '
<input type="hidden" class="list_order"
name="_apop_post_' . self::create_post_sort_key( $tax_data->taxonomy, $tax_key ) . '[post_sort][' . $tax_data->term_id . '][' . $target_post_no_order->ID . ']"
value="' . $sort_num_no_order . '">
</li>';
}
if ( isset( $list ) ) {
return implode( PHP_EOL, $list );
}
}
return '';
}
private static function get_none_sort_post_list( $tax_id, $search_param, $exclude_posts, $tax_name ) {
$args = array(
'post_status' => array( 'publish', 'draft' ),
'posts_per_page' => - 1,
);
$exclude = implode( ',', $exclude_posts );
if ( ! empty( $exclude ) ) {
$args['exclude'] = $exclude;
}
self::create_post_tax_query( $args, $search_param, $tax_name, $tax_id );
return get_posts( $args );
}
public static function create_cat_per_page( $opt_per_page, $type ): array {
$cat_per_page = $opt_per_page[ $type ] ?? 'default';
$checked = '';
@@ -235,19 +238,20 @@ value="' . $sort_num_no_order . '">
$alert = ! $order_param[ $target_key ]['use'] ? '<p>並べ替えを登録するには「変更を保存」をクリックしてください。</p>' : '';
$no_order_class = ! $order_param[ $target_key ]['use'] ? ' no_order' : '';
$list[] = '<li class="product-list' . $no_order_class . '">
<div class="product-list-type-label"><b>' . $target_values[ $target_key ] . '</b></div>
<div class="product-list-sort-type">
<label>
<input type="hidden" name="_' . $name_key . '[' . $target_key . '][use]" value="0"' . self::set_search_normal_checked( $use, 0 ) . '>
<input type="checkbox" name="_' . $name_key . '[' . $target_key . '][use]" value="1"' . self::set_search_normal_checked( $use, 1 ) . '>
<b>' . $target_values[ $target_key ] . '</b>
有効:<input type="checkbox" name="_' . $name_key . '[' . $target_key . '][use]" value="1"' . self::set_search_normal_checked( $use, 1 ) . '>
</label>
&nbsp;&nbsp;
<label><input class="' . $name_key . '" type="radio"
name="_' . $name_key . '[' . $target_key . '][sort]"
value="1"' . self::set_search_normal_checked( $sort, 1 ) . '>昇順</label>
&nbsp;&nbsp;
<label><input class="' . $name_key . '" type="radio"
name="_' . $name_key . '[' . $target_key . '][sort]"
value="2"' . self::set_search_normal_checked( $sort, 2 ) . '>降順</label>
</div>
</li>';
}
@@ -293,18 +297,20 @@ value="' . $sort_num_no_order . '">
}
}
public static function create_disp_class( $disp ) {
public static function create_disp_class( $disp ): string {
if ( ! $disp ) {
return ' class="hide_list"';
}
return '';
}
public static function create_none_select_msg( $str ) {
public static function create_none_select_msg( $str ): string {
return '<p>並べ替えをカスタマイズする' . $str . 'は選択されていません。</p>';
}
public static function none_registerd_alert_msg() {
return '<div class="no_registered_exp">&#9632;の項目は未登録項目です。ドラッグして並び順を変更後に「変更を保存」をクリックしてください。</div>';
public static function none_registered_alert_msg(): string {
return '<div class="no_registered_exp">&#9632;は未登録項目です。ドラッグして並び順を変更後に「変更を保存」をクリックしてください。</div>';
}
}
+49 -15
View File
@@ -1,5 +1,10 @@
@charset "UTF-8";
h3 {
font-weight: normal;
font-size: 16px;
}
.post-order-nav {
width: 95%;
}
@@ -30,8 +35,12 @@
margin-right: 0;
}
.post-setting-box {
margin: 5px 15px;
}
.post-order-box-outer {
width: 95%;
width: 100%;
margin: -1px 0 2em;
border-top: 1px solid #999;
}
@@ -40,11 +49,6 @@
display: none;
}
h3 {
font-weight: normal;
font-size: 16px;
}
.list-orders-outer {
width: 100%;
margin-bottom: 1em;
@@ -54,7 +58,7 @@ h3 {
}
.list-orders-inner {
width: calc((100% - 10px) / 5);
width: calc((100% - 10px) / 2);
margin: 1.5em 1em 0 0;
padding: .5em;
border: 1px solid #999;
@@ -107,8 +111,7 @@ dl.apop_setting_list dd:first-of-type {
}
.product-list {
padding: .5em;
border-radius: 4px;
padding: 1em .5em;
background: #fff;
cursor: move;
color: #4b4b4b;
@@ -116,12 +119,22 @@ dl.apop_setting_list dd:first-of-type {
}
.search_normal_sort .product-list {
padding: 1em .5em;
border-radius: 0px;
display: flex;
}
.search_normal_sort .product-list label:first-of-type {
width: 100px;
.search_normal_sort .product-list-type-label {
width: calc(100% / 2);
display: flex;
justify-content: space-between;
}
.search_normal_sort .product-list-sort-type {
width: 100%;
display: flex;
}
.search_normal_sort .product-list-sort-type label {
width: calc((100% / 4) - 5px);
}
.product-list.no_order {
@@ -145,9 +158,30 @@ dl.apop_setting_list dd:first-of-type {
}
.no_registered_exp {
width: 100%;
margin-top: 1em;
}
@media only screen and (max-width: 1264px) {
.search_normal_sort .product-list {
display: block;
}
.search_normal_sort .product-list-type-label {
width: 100%;
margin-bottom: 1em;
display: block;
}
.search_normal_sort .product-list-sort-type {
width: 100%;
}
.search_normal_sort .product-list-sort-type label {
width: calc((100% / 3) - 5px);
}
}
@media only screen and (max-width: 964px) {
.post-order-nav {
@@ -159,11 +193,11 @@ dl.apop_setting_list dd:first-of-type {
}
.list-orders-inner.search_inner {
width: 100%;
width: auto;
}
.list-orders-inner {
width: 100%;
width: auto;
margin: 1.5em 0 0 0;
}
-2
View File
@@ -10,8 +10,6 @@ jQuery(function ($) {
change_search_order();
change_normal_order();
en_search_normal_sort_btn()
//per page
disp_tax_per_page();
change_normal_per_page();
+25 -79
View File
@@ -1,6 +1,6 @@
<?php
$normal_lists = APOP_UI::get_all_search_normal_posts( 'registered', 'normal' );
$search_lists = APOP_UI::get_all_search_normal_posts( 'registered', 'search' );
$normal_lists = APOP_UI::get_all_search_normal_posts( 'normal' );
$search_lists = APOP_UI::get_all_search_normal_posts( 'search' );
$category_lists = array( 'category' => APOP_UI::get_cat_tag_list( 'cat', 'category' ) );
$tag_lists = array( 'tag_id' => APOP_UI::get_cat_tag_list( 'tag', 'post_tag' ) );
$taxonomy_lists = array( 'taxonomy' => APOP_UI::get_cat_tag_list( 'tax', 'taxonomy' ) );
@@ -8,8 +8,9 @@ $submit_type = APOP_UI::input_post_filter( 'submit_type', 'str' );
$apop_search_order_check = APOP_UI::get_order_type( '_apop_search_order' );
$apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' );
?>
<h2>並べ替え</h2>
<nav class="post-order-nav">
<div class="post-setting-box">
<h2>並べ替え</h2>
<nav class="post-order-nav">
<ul>
<li class="en">通常</li>
<li>検索</li>
@@ -17,8 +18,8 @@ $apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' );
<li>タグ</li>
<li>カスタム分類</li>
</ul>
</nav>
<div class="post-order-box-outer" data-submit_type="<?php echo $submit_type; ?>">
</nav>
<div class="post-order-box-outer" data-submit_type="<?php echo $submit_type; ?>">
<div class="post-order-box">
<div class="list-orders-outer">
<?php $exclude_posts = []; ?>
@@ -44,29 +45,9 @@ $apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' );
</div>
<div class="normal_sort_box">
<?php echo APOP_UI::none_registerd_alert_msg(); ?>
<?php echo APOP_UI::none_registered_alert_msg(); ?>
<ul class="post-order-list">
<?php foreach ( $normal_lists as $i => $normal_list ): $normal_order = $i + 1; ?>
<?php $exclude_posts[] = $normal_list->ID; ?>
<li class="product-list">
<span class="sort-num-label"><?php echo $normal_order; ?></span>
<?php echo $normal_list->post_title; ?>
<input type="hidden" class="list_order"
name="_apop_post_normal[post_sort][<?php echo $normal_list->ID; ?>]"
value="<?php echo $normal_order; ?>">
</li>
<?php endforeach; ?>
<?php $search_none_lists = APOP_UI::get_all_search_normal_posts( 'none', 'normal', $exclude_posts ); ?>
<?php $normal_order = $normal_order ?? 0; ?>
<?php foreach ( $search_none_lists as $i => $search_list ): $normal_order = $normal_order + $i + 1; ?>
<li class="product-list no_order">&#9632;
<span class="sort-num-label"><?php echo $normal_order; ?></span>
<?php echo $search_list->post_title; ?>
<input type="hidden" class="list_order"
name="_apop_post_normal[post_sort][<?php echo $search_list->ID; ?>]"
value="<?php echo $normal_order; ?>">
</li>
<?php endforeach; ?>
<?php echo APOP_UI::get_all_search_normal_posts( 'normal' ); ?>
</ul>
</div>
@@ -103,29 +84,9 @@ $apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' );
</div>
<div class="search_sort_box">
<?php echo APOP_UI::none_registerd_alert_msg(); ?>
<?php echo APOP_UI::none_registered_alert_msg(); ?>
<ul class="post-order-list">
<?php foreach ( $search_lists as $i => $search_list ): $search_order = $i + 1; ?>
<?php $exclude_posts[] = $search_list->ID; ?>
<li class="product-list">
<span class="sort-num-label"><?php echo $search_order; ?></span>
<?php echo $search_list->post_title; ?>
<input type="hidden" class="list_order"
name="_apop_post_search[post_sort][<?php echo $search_list->ID; ?>]"
value="<?php echo $search_order; ?>">
</li>
<?php endforeach; ?>
<?php $search_none_lists = APOP_UI::get_all_search_normal_posts( 'none', 'search', $exclude_posts ); ?>
<?php $search_order = $search_order ?? 0; ?>
<?php foreach ( $search_none_lists as $i => $search_list ): $search_order = $search_order + $i + 1; ?>
<li class="product-list no_order">&#9632;
<span class="sort-num-label"><?php echo $search_order; ?></span>
<?php echo $search_list->post_title; ?>
<input type="hidden" class="list_order"
name="_apop_post_search[post_sort][<?php echo $search_list->ID; ?>]"
value="<?php echo $search_order; ?>">
</li>
<?php endforeach; ?>
<?php echo APOP_UI::get_all_search_normal_posts( 'search' ); ?>
</ul>
</div>
@@ -138,26 +99,21 @@ $apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' );
</div>
</div>
<div class="post-order-box">
<?php if ( count( $taxonomy_lists['taxonomy'] ) > 0 ): ?>
<?php echo APOP_UI::none_registerd_alert_msg(); ?>
<?php endif; ?>
<?php foreach ( $category_lists as $tax_key => $tax_list ) : ?>
<div class="list-orders-outer">
<?php if ( count( $tax_list ) > 0 ): $exclude_posts = []; ?>
<?php if ( count( $tax_list ) > 0 ): ?>
<?php echo APOP_UI::none_registered_alert_msg(); ?>
<?php foreach ( $tax_list as $tax_data ): ?>
<div class="list-orders-inner">
<form action="" method="post">
<?php wp_nonce_field( 'sh_options' ); ?>
<h3><?php echo $tax_data->name; ?></h3>
<ul class="post-order-list">
<?php
list( $product_order_list, $exclude_posts, $sort_num ) = APOP_UI::create_order_list( $tax_data, $tax_key, $exclude_posts );
echo $product_order_list;
echo APOP_UI::create_product_none_order_list( $tax_data, $tax_key, $exclude_posts, $sort_num );
?>
<?php echo APOP_UI::create_order_list( $tax_data, $tax_key ); ?>
</ul>
<input type="hidden" name="submit_type" value="2">
<p class="submit post-order"><input type="submit" name="Submit" class="button-primary"
<p class="submit post-order"><input type="submit" name="Submit"
class="button-primary"
value="変更を保存"/></p>
</form>
</div>
@@ -169,26 +125,21 @@ $apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' );
<?php endforeach; ?>
</div>
<div class="post-order-box">
<?php if ( count( $taxonomy_lists['taxonomy'] ) > 0 ): ?>
<?php echo APOP_UI::none_registerd_alert_msg(); ?>
<?php endif; ?>
<?php foreach ( $tag_lists as $tax_key => $tax_list ) : ?>
<div class="list-orders-outer">
<?php if ( count( $tax_list ) > 0 ): $exclude_posts = []; ?>
<?php if ( count( $tax_list ) > 0 ): ?>
<?php echo APOP_UI::none_registered_alert_msg(); ?>
<?php foreach ( $tax_list as $tax_data ): ?>
<div class="list-orders-inner">
<form action="" method="post">
<?php wp_nonce_field( 'sh_options' ); ?>
<h3><?php echo $tax_data->name; ?></h3>
<ul class="post-order-list">
<?php
list( $product_order_list, $exclude_posts, $sort_num ) = APOP_UI::create_order_list( $tax_data, $tax_key, $exclude_posts );
echo $product_order_list;
echo APOP_UI::create_product_none_order_list( $tax_data, $tax_key, $exclude_posts, $sort_num );
?>
<?php echo APOP_UI::create_order_list( $tax_data, $tax_key ); ?>
</ul>
<input type="hidden" name="submit_type" value="3">
<p class="submit post-order"><input type="submit" name="Submit" class="button-primary"
<p class="submit post-order"><input type="submit" name="Submit"
class="button-primary"
value="変更を保存"/></p>
</form>
</div>
@@ -200,24 +151,18 @@ $apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' );
<?php endforeach; ?>
</div>
<div class="post-order-box">
<?php if ( count( $taxonomy_lists['taxonomy'] ) > 0 ): ?>
<?php echo APOP_UI::none_registerd_alert_msg(); ?>
<?php endif; ?>
<?php foreach ( $taxonomy_lists as $tax_key => $taxonomy_list ): ?>
<div class="list-orders-outer">
<?php foreach ( $taxonomy_list as $tax_list ) : ?>
<?php if ( count( $taxonomy_list ) > 0 ): $exclude_posts = []; ?>
<?php if ( count( $taxonomy_list ) > 0 ): ?>
<?php echo APOP_UI::none_registered_alert_msg(); ?>
<?php foreach ( $tax_list as $tax_data ): ?>
<div class="list-orders-inner">
<form action="" method="post">
<?php wp_nonce_field( 'sh_options' ); ?>
<h3><?php echo $tax_data->name; ?></h3>
<ul class="post-order-list">
<?php
list( $product_order_list, $exclude_posts, $sort_num ) = APOP_UI::create_order_list( $tax_data, $tax_key, $exclude_posts );
echo $product_order_list;
echo APOP_UI::create_product_none_order_list( $tax_data, $tax_key, $exclude_posts, $sort_num );
?>
<?php echo APOP_UI::create_order_list( $tax_data, $tax_key ); ?>
</ul>
<input type="hidden" name="submit_type" value="4">
<p class="submit post-order"><input type="submit" name="Submit"
@@ -234,4 +179,5 @@ $apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' );
</div>
<?php endforeach; ?>
</div>
</div>
</div>
+9 -4
View File
@@ -12,6 +12,7 @@ $all_tax = APOP_UI::get_all_taxonomies( 'taxonomy' );
$opt_per_page = get_option( '_apop_per_page' );
$opt_tag = get_option( '_apop_tag_order' );
$opt_tax = get_option( '_apop_tax_order' );
$default_per_page = get_option( 'posts_per_page' );
?>
<h2>設定</h2>
<table class="form-table">
@@ -25,7 +26,8 @@ $all_tax = APOP_UI::get_all_taxonomies( 'taxonomy' );
<li>
<label>
<input class="per_page_search" type="radio" name="_apop_per_page[search]"
value="default"<?php checked( $per_page_data['_per_page'], 'default' ); ?>>表示設定に従う</label>
value="default"<?php checked( $per_page_data['_per_page'], 'default' ); ?>>表示設定に従う<?php echo $default_per_page; ?>
件)</label>
</li>
<li><label>
<input class="per_page_search" type="radio" name="_apop_per_page[search]"
@@ -82,7 +84,8 @@ $all_tax = APOP_UI::get_all_taxonomies( 'taxonomy' );
<li>
<label>
<input class="per_page_cat" type="radio" name="_apop_per_page[category]"
value="default"<?php checked( $per_page_data['_per_page'], 'default' ); ?>>表示設定に従う</label>
value="default"<?php checked( $per_page_data['_per_page'], 'default' ); ?>>表示設定に従う<?php echo $default_per_page; ?>
件)</label>
</li>
<li><label>
<input class="per_page_cat" type="radio" name="_apop_per_page[category]"
@@ -143,7 +146,8 @@ $all_tax = APOP_UI::get_all_taxonomies( 'taxonomy' );
<li>
<label>
<input class="per_page_tag" type="radio" name="_apop_per_page[tag]"
value="default"<?php checked( $per_page_data['_per_page'], 'default' ); ?>>表示設定に従う</label>
value="default"<?php checked( $per_page_data['_per_page'], 'default' ); ?>>表示設定に従う<?php echo $default_per_page; ?>
件)</label>
</li>
<li><label>
<input class="per_page_tag" type="radio" name="_apop_per_page[tag]"
@@ -207,7 +211,8 @@ $all_tax = APOP_UI::get_all_taxonomies( 'taxonomy' );
<li>
<label>
<input class="per_page_tax" type="radio" name="_apop_per_page[tax]"
value="default"<?php checked( $per_page_data['_per_page'], 'default' ); ?>>表示設定に従う</label>
value="default"<?php checked( $per_page_data['_per_page'], 'default' ); ?>>表示設定に従う<?php echo $default_per_page; ?>
件)</label>
</li>
<li><label>
<input class="per_page_tax" type="radio" name="_apop_per_page[tax]"
+1 -3
View File
@@ -1,3 +1 @@
<div class="updated fade">
<p><strong>設定を保存しました</strong></p>
</div>
<div id="settings_updated" class="updated notice is-dismissible"><p><strong>設定を保存しました</strong></p></div>
+30 -9
View File
@@ -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,20 +86,42 @@ 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',
'meta_query' => self::get_all_post_args( '_apop_normal_order' ),
'orderby' => array( 'meta_value_num' => 'ASC' ),
);
} else {