Merge pull request 'WP PLUGIN ソート対象拡張' (#3) from 修正_タクソノミーソートのカスタムフィールド対応 into master

Reviewed-on: https://develop.n-k-y.net/repo/WP_PLUGIN/POST_ORDER_BY_ARCHIVE/pulls/3
This commit was merged in pull request #3.
This commit is contained in:
nobu
2021-05-10 21:36:10 +09:00
9 changed files with 317 additions and 178 deletions
+16
View File
@@ -125,10 +125,26 @@ if ( ! class_exists( 'APOP' ) ) {
//------------------------------------- //-------------------------------------
// タクソノミー // タクソノミー
// ------------------------------------ // ------------------------------------
$tax_sort_type = APOP_UI::input_post_filter( '_apop_tax_sort_type', 'array' );
$apop_tax_order_param = APOP_UI::input_post_filter( '_apop_tax_order_param', 'array' );
$apop_post_category = APOP_UI::input_post_filter( '_apop_post_category', 'array' ); $apop_post_category = APOP_UI::input_post_filter( '_apop_post_category', 'array' );
$apop_post_post_tag = APOP_UI::input_post_filter( '_apop_post_post_tag', 'array' ); $apop_post_post_tag = APOP_UI::input_post_filter( '_apop_post_post_tag', 'array' );
$apop_post_tax = APOP_UI::input_post_filter( '_apop_post_tax', 'array' ); $apop_post_tax = APOP_UI::input_post_filter( '_apop_post_tax', 'array' );
//カテゴリーのソートタイプ設定
if ( $tax_sort_type ) {
check_admin_referer( 'sh_options' );
update_option( '_apop_tax_sort_type', $tax_sort_type );
require_once self::TEMPLATE_DIR . 'success.php';
}
//カテゴリーの標準ソートパラメータ
if ( $apop_tax_order_param ) {
check_admin_referer( 'sh_options' );
update_option( '_apop_tax_order_param', $apop_tax_order_param );
require_once self::TEMPLATE_DIR . 'success.php';
}
//カテゴリーの投稿表示順設定 //カテゴリーの投稿表示順設定
if ( $apop_post_category ) { if ( $apop_post_category ) {
check_admin_referer( 'sh_options' ); check_admin_referer( 'sh_options' );
+98 -21
View File
@@ -15,7 +15,9 @@ if ( ! class_exists( 'APOP_UI' ) ) {
return $type_data; return $type_data;
} }
public static function get_all_search_normal_posts( $key ): string { public static function get_all_search_normal_posts(
$key
): string {
$meta_key = '_apop_post_' . $key; $meta_key = '_apop_post_' . $key;
$args = self::create_search_normal_args( $meta_key ); $args = self::create_search_normal_args( $meta_key );
$posts_data = get_posts( $args ); $posts_data = get_posts( $args );
@@ -100,14 +102,17 @@ if ( ! class_exists( 'APOP_UI' ) ) {
'hide_empty' => 0, 'hide_empty' => 0,
'include' => $tax_id, 'include' => $tax_id,
); );
$tax_data[] = get_terms( $args ); $tax_data = array_merge( $tax_data, get_terms( $args ) );
} }
} }
if ( count( $tax_data ) > 0 ) {
return $tax_data; return $tax_data;
} }
return array();
}
private static function create_tax_term( $opt, $key ) { private static function create_tax_term( $opt, $key ) {
$include = array(); $include = array();
foreach ( $opt['target_cat'] as $tax_id => $status ) { foreach ( $opt['target_cat'] as $tax_id => $status ) {
@@ -261,22 +266,38 @@ value="' . $sort_num . '">
); );
} }
public static function create_search_normal_list( $type ): array { public static function create_search_normal_list( $type, $id = null ): array {
$name_key = 'apop_' . $type . '_order_param'; $name_keys = self::create_name_keys( $id, $type );
$order_param = get_option( '_' . $name_key ); $name_key = $name_keys['name_key'];
$get_option_key = $name_keys['get_option_key'];
$order_param_base = get_option( $get_option_key );
$order_param = '';
if ( is_null( $id ) ) {
$order_param = $order_param_base;
}
if ( isset( $order_param_base[ $id ] ) ) {
$order_param = $order_param_base[ $id ];
}
$target_keys = self::set_search_normal_target_keys( $order_param ); $target_keys = self::set_search_normal_target_keys( $order_param );
$target_values = array( $target_values = array(
'date' => '登録日', 'date' => '登録日',
'title' => 'タイトル', 'title' => 'タイトル',
'ID' => 'ID', 'ID' => 'ID',
'modified' => '更新日', 'modified' => '更新日',
'custom_field' => 'カスタムフィールド',
); );
$list = array(); $list = array();
foreach ( $target_keys as $target_key ) { foreach ( $target_keys as $target_key ) {
$use = $order_param[ $target_key ]['use'] ?? 0; $cnv_order_params = self::set_order_list_param( $order_param, $target_key );
$sort = $order_param[ $target_key ]['sort'] ?? 2; $use = $cnv_order_params['use'];
$alert = ! $order_param[ $target_key ]['use'] ? '<p>並べ替えを登録するには「変更を保存」をクリックしてください。</p>' : ''; $sort = $cnv_order_params['sort'];
$no_order_class = ! $order_param[ $target_key ]['use'] ? ' no_order' : ''; $alert = $cnv_order_params['alert'];
$no_order_class = $cnv_order_params['no_order_class'];
if ( $target_key == 'custom_field' ) {
$meta_key = $cnv_order_params['custom_field']['meta_key'];
$value_type = $cnv_order_params['custom_field']['value_type'];
$field_metakey_input = self::create_custom_field_sort_type( $name_key, $target_key, $meta_key, $value_type );
}
$list[] = '<li class="product-list' . $no_order_class . '"> $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-type-label"><b>' . $target_values[ $target_key ] . '</b></div>
<div class="product-list-sort-type"> <div class="product-list-sort-type">
@@ -284,11 +305,12 @@ value="' . $sort_num . '">
<input type="hidden" name="_' . $name_key . '[' . $target_key . '][use]" value="0"' . self::set_search_normal_checked( $use, 0 ) . '> <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 ) . '> 有効:<input type="checkbox" name="_' . $name_key . '[' . $target_key . '][use]" value="1"' . self::set_search_normal_checked( $use, 1 ) . '>
</label> </label>
<label><input class="' . $name_key . '" type="radio" <label>
<input class="' . $name_key . '" type="radio"
name="_' . $name_key . '[' . $target_key . '][sort]" name="_' . $name_key . '[' . $target_key . '][sort]"
value="1"' . self::set_search_normal_checked( $sort, 1 ) . '>昇順</label> value="1"' . self::set_search_normal_checked( $sort, 1 ) . '>昇順</label>
<label>
<label><input class="' . $name_key . '" type="radio" <input class="' . $name_key . '" type="radio"
name="_' . $name_key . '[' . $target_key . '][sort]" name="_' . $name_key . '[' . $target_key . '][sort]"
value="2"' . self::set_search_normal_checked( $sort, 2 ) . '>降順</label> value="2"' . self::set_search_normal_checked( $sort, 2 ) . '>降順</label>
</div> </div>
@@ -298,9 +320,71 @@ value="' . $sort_num . '">
return array( return array(
implode( PHP_EOL, $list ), implode( PHP_EOL, $list ),
$alert, $alert,
$field_metakey_input,
); );
} }
private static function create_custom_field_sort_type( $name_key, $target_key, $meta_key, $value_type ): string {
return '<div class="sort_custom_field">カスタムフィールドキー:
<input type="text" name="_' . $name_key . '[' . $target_key . '][field][meta_key]" value="' . $meta_key . '">
値タイプ:
<label><input type="radio"
name="_' . $name_key . '[' . $target_key . '][field][value_type]"
value="meta_value"' . self::set_search_normal_checked( $value_type, 'meta_value' ) . '>テキスト</label>
<label><input type="radio"
name="_' . $name_key . '[' . $target_key . '][field][value_type]"
value="meta_value_num"' . self::set_search_normal_checked( $value_type, 'meta_value_num' ) . '>数値</label>
</div>';
}
private static function set_order_list_param( $order_param, $target_key ): array {
$param = array(
'use' => 0,
'sort' => 2,
'alert' => '<p>並べ替えを登録するには「変更を保存」をクリックしてください。</p>',
'no_order_class' => ' no_order',
);
if ( $target_key == 'custom_field' ) {
$param['custom_field'] = array(
'meta_key' => '',
'value_type' => 'meta_value',
);
}
if ( isset( $order_param[ $target_key ] ) ) {
$param = array(
'use' => $order_param[ $target_key ]['use'] ?? 0,
'sort' => $order_param[ $target_key ]['sort'] ?? 2,
'alert' => ! $order_param[ $target_key ]['use'] ? '<p>並べ替えを登録するには「変更を保存」をクリックしてください。</p>' : '',
'no_order_class' => ! $order_param[ $target_key ]['use'] ? ' no_order' : '',
);
if ( $target_key == 'custom_field' ) {
$param['custom_field'] = array(
'meta_key' => $order_param[ $target_key ]['field']['meta_key'] ?? '',
'value_type' => $order_param[ $target_key ]['field']['value_type'] ?? 'meta_value',
);
}
}
return $param;
}
private static function create_name_keys( $id, $type ): array {
if ( is_null( $id ) ) {
return array(
'name_key' => 'apop_' . $type . '_order_param',
'get_option_key' => '_' . 'apop_' . $type . '_order_param',
);
} else {
return array(
'name_key' => 'apop_tax_order_param[' . $id . ']',
'get_option_key' => '_apop_tax_order_param',
);
}
}
private static function set_search_normal_target_keys( $post_apop_search_order_param ) { private static function set_search_normal_target_keys( $post_apop_search_order_param ) {
if ( $post_apop_search_order_param ) { if ( $post_apop_search_order_param ) {
return array_keys( $post_apop_search_order_param ); return array_keys( $post_apop_search_order_param );
@@ -311,6 +395,7 @@ value="' . $sort_num . '">
'title', 'title',
'ID', 'ID',
'modified', 'modified',
'custom_field'
); );
} }
@@ -337,14 +422,6 @@ value="' . $sort_num . '">
} }
} }
public static function create_disp_class( $disp ): string {
if ( ! $disp ) {
return ' class="hide_list"';
}
return '';
}
public static function create_none_select_msg( $str ): string { public static function create_none_select_msg( $str ): string {
return '<p>並べ替えをカスタマイズする' . $str . 'は選択されていません。</p>'; return '<p>並べ替えをカスタマイズする' . $str . 'は選択されていません。</p>';
} }
+10 -21
View File
@@ -52,30 +52,21 @@ h3 {
.list-orders-outer { .list-orders-outer {
width: 100%; width: 100%;
margin-bottom: 1em; margin-bottom: 1em;
display: flex;
justify-content: flex-start;
flex-wrap: wrap;
} }
.list-orders-inner { .list-orders-inner {
width: 45%;; width: 50%;
margin: 1.5em 1em 0 0; margin: 1.5em 1em 0 0;
padding: .5em; padding: .5em;
border: 1px solid #999; border: 1px solid #999;
position: relative; position: relative;
} }
.list-orders-inner.search_inner { .sort_menu_list {
width: 50%;
}
.apop_normal_order_target,
.apop_search_order_target {
display: flex; display: flex;
} }
.apop_normal_order_target li:first-child, .sort_menu_list li:first-child {
.apop_search_order_target li:first-child {
margin-right: 2em; margin-right: 2em;
} }
@@ -123,8 +114,6 @@ dl.apop_setting_list dd:first-of-type {
.search_normal_sort .product-list-type-label { .search_normal_sort .product-list-type-label {
width: calc(100% / 2); width: calc(100% / 2);
display: flex;
justify-content: space-between;
} }
.search_normal_sort .product-list-sort-type { .search_normal_sort .product-list-sort-type {
@@ -152,9 +141,9 @@ dl.apop_setting_list dd:first-of-type {
content: ""; content: "";
} }
.hide_list { /*.hide_list {*/
display: none; /* display: none;*/
} /*}*/
.no_registered_exp { .no_registered_exp {
width: 100%; width: 100%;
@@ -172,6 +161,10 @@ dl.apop_setting_list dd:first-of-type {
border-top: 1px solid #ccc; border-top: 1px solid #ccc;
} }
.sort_custom_field{
width: 100%;
}
@media only screen and (max-width: 1264px) { @media only screen and (max-width: 1264px) {
.search_normal_sort .product-list { .search_normal_sort .product-list {
display: block; display: block;
@@ -202,10 +195,6 @@ dl.apop_setting_list dd:first-of-type {
display: block;; display: block;;
} }
.list-orders-inner.search_inner {
width: auto;
}
.list-orders-inner { .list-orders-inner {
width: auto; width: auto;
margin: 1.5em 0 0 0; margin: 1.5em 0 0 0;
+44 -8
View File
@@ -7,8 +7,9 @@ jQuery(function ($) {
order_list(); order_list();
//order type //order type
change_search_order(); // change_search_order();
change_normal_order(); // change_normal_order();
change_sort_box();
//Tax select //Tax select
select_tax(); select_tax();
@@ -28,7 +29,7 @@ jQuery(function ($) {
$('.post-order-nav li:eq(' + submit_type + ')').addClass('en'); $('.post-order-nav li:eq(' + submit_type + ')').addClass('en');
$('.post-order-box:eq(' + submit_type + ')').show() $('.post-order-box:eq(' + submit_type + ')').show()
order_nav_list.click(function () { order_nav_list.on('click', function () {
if (!$(this).hasClass('en')) { if (!$(this).hasClass('en')) {
let target_index = $(this).index(); let target_index = $(this).index();
order_nav_list.removeClass('en'); order_nav_list.removeClass('en');
@@ -69,7 +70,7 @@ jQuery(function ($) {
}); });
$('.normal_sort_box:eq(' + default_index + ')').show().find('input').prop('disabled', false); $('.normal_sort_box:eq(' + default_index + ')').show().find('input').prop('disabled', false);
s_radio.click(function () { s_radio.on('click', function () {
let target_index = $(this).val() - 1; let target_index = $(this).val() - 1;
s_box.hide().find('input').each(function () { s_box.hide().find('input').each(function () {
$(this).prop('disabled', true); $(this).prop('disabled', true);
@@ -89,7 +90,7 @@ jQuery(function ($) {
$('.search_sort_box:eq(' + default_index + ')').show().find('input').prop('disabled', false); $('.search_sort_box:eq(' + default_index + ')').show().find('input').prop('disabled', false);
s_radio.click(function () { s_radio.on('click', function () {
let target_index = $(this).val() - 1; let target_index = $(this).val() - 1;
s_box.hide().find('input').each(function () { s_box.hide().find('input').each(function () {
$(this).prop('disabled', true); $(this).prop('disabled', true);
@@ -98,6 +99,41 @@ jQuery(function ($) {
}) })
} }
function change_sort_box() {
let parent_selector = $('.list-orders-inner');
let parent_selector_size = parent_selector.length;
let s_radio = $('.sort_menu');
let s_box = $('.sort_box');
s_box.hide().find('input').each(function () {
$(this).prop('disabled', true);
});
for (let i = 0; i < parent_selector_size; i++) {
let my_target = $('.list-orders-inner:eq(' + i + ')');
let default_index = my_target.find('.sort_menu_list').data('order_target') - 1;
if (typeof default_index !== "undefined") {
my_target.find('.sort_box:eq(' + default_index + ')').show().find('input').prop('disabled', false);
} else if (isNaN(default_index)) {
my_target.find('.sort_box:eq(0)').show().find('input').prop('disabled', false);
}
}
s_radio.on('click', function () {
let target_index = $(this).val() - 1;
$(this).parents('.list-orders-inner')
.find('.sort_box').hide()
.find('input').each(function () {
$(this).prop('disabled', true);
});
$(this).parents('.list-orders-inner')
.find('.sort_box:eq(' + target_index + ')').show()
.find('input').prop('disabled', false);
})
}
function select_tax() { function select_tax() {
let select_cat_checkbox = $('.select_cat_checkbox'); let select_cat_checkbox = $('.select_cat_checkbox');
let input_chk_size = select_cat_checkbox.length; let input_chk_size = select_cat_checkbox.length;
@@ -112,7 +148,7 @@ jQuery(function ($) {
} }
} }
select_cat_checkbox.click(function () { select_cat_checkbox.on('click', function () {
let checked = $(this).prop('checked'); let checked = $(this).prop('checked');
if (checked) { if (checked) {
$(this).parent().parent().siblings('.select_per_page').show(200); $(this).parent().parent().siblings('.select_per_page').show(200);
@@ -133,7 +169,7 @@ jQuery(function ($) {
per_page_input.prop('disabled', false); per_page_input.prop('disabled', false);
} }
per_page_cat.click(function () { per_page_cat.on('click', function () {
if ($(this).val() != 'default' && $(this).val() != '-1' && $(this).val() != 'all') { if ($(this).val() != 'default' && $(this).val() != '-1' && $(this).val() != 'all') {
per_page_input.prop('disabled', false); per_page_input.prop('disabled', false);
} else { } else {
@@ -157,7 +193,7 @@ jQuery(function ($) {
} }
} }
$('.per_page_cat').click(function () { $('.per_page_cat').on('click', function () {
if ($(this).hasClass('set_number')) { if ($(this).hasClass('set_number')) {
$(this).siblings('.per_page_cat_input').prop('disabled', false); $(this).siblings('.per_page_cat_input').prop('disabled', false);
} else { } else {
+43 -114
View File
@@ -1,12 +1,5 @@
<?php <?php
$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' ) );
$submit_type = APOP_UI::input_post_filter( 'submit_type', 'str' ); $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' );
?> ?>
<div class="post-setting-box"> <div class="post-setting-box">
<h2>並べ替え</h2> <h2>並べ替え</h2>
@@ -22,163 +15,99 @@ $apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' );
<div class="post-order-box-outer" data-submit_type="<?php echo $submit_type; ?>"> <div class="post-order-box-outer" data-submit_type="<?php echo $submit_type; ?>">
<div class="post-order-box"> <div class="post-order-box">
<div class="list-orders-outer"> <div class="list-orders-outer">
<?php $exclude_posts = []; ?> <div class="list-orders-inner">
<div class="list-orders-inner search_inner">
<form action="" method="post"> <form action="" method="post">
<h3>通常</h3>
<?php wp_nonce_field( 'sh_options' ); ?> <?php wp_nonce_field( 'sh_options' ); ?>
<ul class="apop_normal_order_target" <?php
data-normal_order_target="<?php echo $apop_normal_check; ?>"> $order_target_type = '_apop_normal_order';
<li><label> $order_target = APOP_UI::get_order_type( $order_target_type );
<input class="apop_normal_order" type="radio" name="_apop_normal_order" ?>
value="1"<?php checked( $apop_normal_check, 1 ); ?>>標準</label></li> <?php include APOP_PLUGIN_PATH . 'template/order_parts_menu.php'; ?>
<li><label>
<input class="apop_normal_order" type="radio" name="_apop_normal_order"
value="2"<?php checked( $apop_normal_check, 2 ); ?>>ドラッグソート</label></li>
</ul>
<hr> <hr>
<div class="normal_sort_box"> <div class="sort_box">
<?php list( $list, $alert ) = APOP_UI::create_search_normal_list( 'normal' ); ?> <?php list( $list, $alert, $field_metakey_input ) = APOP_UI::create_search_normal_list( 'normal' ); ?>
<?php echo $alert; ?> <?php echo $alert; ?>
<ul class="post-order-list search_normal_sort"> <ul class="post-order-list search_normal_sort">
<?php echo $list; ?> <?php echo $list; ?>
</ul> </ul>
<?php echo $field_metakey_input; ?>
</div> </div>
<div class="sort_box">
<div class="normal_sort_box">
<?php echo APOP_UI::none_registered_alert_msg(); ?> <?php echo APOP_UI::none_registered_alert_msg(); ?>
<ul class="post-order-list"> <ul class="post-order-list">
<?php echo APOP_UI::get_all_search_normal_posts( 'normal' ); ?> <?php echo APOP_UI::get_all_search_normal_posts( 'normal' ); ?>
</ul> </ul>
</div> </div>
<input type="hidden" name="submit_type" value="0"> <input type="hidden" name="submit_type" value="0">
<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> value="変更を保存"/></p>
</form> </form>
</div> </div>
</div> </div>
</div> </div>
<div class="post-order-box"> <div class="post-order-box">
<div class="list-orders-outer"> <div class="list-orders-outer">
<?php $exclude_posts = []; ?> <div class="list-orders-inner">
<div class="list-orders-inner search_inner">
<form action="" method="post"> <form action="" method="post">
<h3>検索</h3>
<?php wp_nonce_field( 'sh_options' ); ?> <?php wp_nonce_field( 'sh_options' ); ?>
<ul class="apop_search_order_target" <?php
data-search_order_target="<?php echo $apop_search_order_check; ?>"> $order_target_type = '_apop_search_order';
<li><label> $order_target = APOP_UI::get_order_type( $order_target_type );
<input class="apop_search_order" type="radio" name="_apop_search_order" ?>
value="1"<?php checked( $apop_search_order_check, 1 ); ?>>標準</label></li> <?php include APOP_PLUGIN_PATH . 'template/order_parts_menu.php'; ?>
<li><label>
<input class="apop_search_order" type="radio" name="_apop_search_order"
value="2"<?php checked( $apop_search_order_check, 2 ); ?>>ドラッグソート</label>
</li>
</ul>
<hr> <hr>
<div class="search_sort_box"> <div class="sort_box">
<?php list( $list, $alert ) = APOP_UI::create_search_normal_list( 'search' ); ?> <?php list( $list, $alert, $field_metakey_input ) = APOP_UI::create_search_normal_list( 'search' ); ?>
<?php echo $alert; ?> <?php echo $alert; ?>
<ul class="post-order-list search_normal_sort"> <ul class="post-order-list search_normal_sort">
<?php echo $list; ?> <?php echo $list; ?>
</ul> </ul>
<?php echo $field_metakey_input; ?>
</div> </div>
<div class="sort_box">
<div class="search_sort_box">
<?php echo APOP_UI::none_registered_alert_msg(); ?> <?php echo APOP_UI::none_registered_alert_msg(); ?>
<ul class="post-order-list"> <ul class="post-order-list">
<?php echo APOP_UI::get_all_search_normal_posts( 'search' ); ?> <?php echo APOP_UI::get_all_search_normal_posts( 'search' ); ?>
</ul> </ul>
</div> </div>
<input type="hidden" name="submit_type" value="1"> <input type="hidden" name="submit_type" value="1">
<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> value="変更を保存"/></p>
</form> </form>
</div> </div>
</div> </div>
</div> </div>
<div class="post-order-box"> <div class="post-order-box">
<?php foreach ( $category_lists as $tax_key => $tax_list ) : ?> <div class="tax_sort_box">
<div class="list-orders-outer"> <?php
<?php if ( count( $tax_list ) > 0 ): ?> $tax_lists = array( 'category' => APOP_UI::get_cat_tag_list( 'cat', 'category' ) );
<?php echo APOP_UI::none_registered_alert_msg(); ?> $tax_title_text = 'カテゴリー';
<?php foreach ( $tax_list as $tax_data ): ?> $submit_type_number = 2;
<div class="list-orders-inner"> ?>
<form action="" method="post"> <?php include APOP_PLUGIN_PATH . 'template/order_parts_taxonomy.php'; ?>
<?php wp_nonce_field( 'sh_options' ); ?>
<h3><?php echo $tax_data->name; ?></h3>
<ul class="post-order-list">
<?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"
value="変更を保存"/></p>
</form>
</div> </div>
<?php endforeach; ?>
<?php else: ?>
<?php echo APOP_UI::create_none_select_msg( 'カテゴリー' ); ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div> </div>
<div class="post-order-box"> <div class="post-order-box">
<?php foreach ( $tag_lists as $tax_key => $tax_list ) : ?> <div class="tax_sort_box">
<div class="list-orders-outer"> <?php
<?php if ( count( $tax_list ) > 0 ): ?> $tax_lists = array( 'tag_id' => APOP_UI::get_cat_tag_list( 'tag', 'post_tag' ) );
<?php echo APOP_UI::none_registered_alert_msg(); ?> $tax_title_text = 'タグ';
<?php foreach ( $tax_list as $tax_data ): ?> $submit_type_number = 3;
<div class="list-orders-inner"> ?>
<form action="" method="post"> <?php include APOP_PLUGIN_PATH . 'template/order_parts_taxonomy.php'; ?>
<?php wp_nonce_field( 'sh_options' ); ?>
<h3><?php echo $tax_data->name; ?></h3>
<ul class="post-order-list">
<?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"
value="変更を保存"/></p>
</form>
</div> </div>
<?php endforeach; ?>
<?php else: ?>
<?php echo APOP_UI::create_none_select_msg( 'タグ' ); ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div> </div>
<div class="post-order-box"> <div class="post-order-box">
<?php foreach ( $taxonomy_lists as $tax_key => $taxonomy_list ): ?> <div class="tax_sort_box">
<div class="list-orders-outer"> <?php
<?php foreach ( $taxonomy_list as $tax_list ) : ?> $tax_lists = array( 'taxonomy' => APOP_UI::get_cat_tag_list( 'tax', 'taxonomy' ) );
<?php if ( count( $taxonomy_list ) > 0 ): ?> $tax_title_text = 'カスタム分類';
<?php echo APOP_UI::none_registered_alert_msg(); ?> $submit_type_number = 4;
<?php foreach ( $tax_list as $tax_data ): ?> ?>
<div class="list-orders-inner"> <?php include APOP_PLUGIN_PATH . 'template/order_parts_taxonomy.php'; ?>
<form action="" method="post">
<?php wp_nonce_field( 'sh_options' ); ?>
<h3><?php echo $tax_data->name; ?></h3>
<ul class="post-order-list">
<?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"
class="button-primary"
value="変更を保存"/></p>
</form>
</div> </div>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php if ( count( $taxonomy_lists['taxonomy'] ) == 0 ): ?>
<?php echo APOP_UI::create_none_select_msg( 'カスタム分類' ); ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div> </div>
</div> </div>
</div> </div>
+11
View File
@@ -0,0 +1,11 @@
<?php if ( isset( $order_target, $order_target_type ) ): ?>
<ul class="sort_menu_list"
data-order_target="<?php echo $order_target; ?>">
<li><label>
<input class="sort_menu" type="radio" name="<?php echo $order_target_type; ?>"
value="1"<?php checked( $order_target, 1 ); ?>>標準+カスタムフィールドソート</label></li>
<li><label>
<input class="sort_menu" type="radio" name="<?php echo $order_target_type; ?>"
value="2"<?php checked( $order_target, 2 ); ?>>ドラッグソート</label></li>
</ul>
<?php endif;
+61
View File
@@ -0,0 +1,61 @@
<?php if ( isset( $tax_lists, $tax_title_text, $submit_type_number ) ): ?>
<?php foreach ( $tax_lists as $tax_key => $tax_list ) : ?>
<div class="list-orders-outer">
<?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>
<?php
$order_target_data = get_option( '_apop_tax_sort_type' );
if ( isset( $order_target_data[ $tax_data->term_id ] ) ) {
$order_target = $order_target_data[ $tax_data->term_id ];
} else {
$order_target = 1;
}
?>
<ul class="sort_menu_list"
data-order_target="<?php echo $order_target; ?>">
<li>
<label>
<input class="sort_menu" type="radio"
name="_apop_tax_sort_type[<?php echo $tax_data->term_id; ?>]"
value="1"<?php checked( $order_target, 1 ); ?>>ドラッグソート</label>
</li>
<li>
<label>
<input class="sort_menu" type="radio"
name="_apop_tax_sort_type[<?php echo $tax_data->term_id; ?>]"
value="2"<?php checked( $order_target, 2 ); ?>>標準+カスタムフィールドソート</label>
</li>
</ul>
<div class="sort_box">
<ul class="post-order-list">
<?php echo APOP_UI::create_order_list( $tax_data, $tax_key ); ?>
</ul>
</div>
<div class="sort_box">
<?php list( $list, $alert, $field_metakey_input ) = APOP_UI::create_search_normal_list( 'tax', $tax_data->term_id ); ?>
<?php echo $alert; ?>
<ul class="post-order-list search_normal_sort">
<?php echo $list; ?>
</ul>
<?php echo $field_metakey_input; ?>
</div>
<input type="hidden" name="submit_type" value="<?php echo $submit_type_number; ?>">
<p class="submit post-order"><input type="submit" name="Submit"
class="button-primary"
value="変更を保存"/></p>
<input type="hidden" name="sort_type[cat]" value="1">
</form>
</div>
<?php endforeach; ?>
<?php else: ?>
<?php echo APOP_UI::create_none_select_msg( $tax_title_text ); ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php endif;
+2
View File
@@ -10,8 +10,10 @@ $param_settings = array(
'_apop_per_page', '_apop_per_page',
'_apop_normal_order', '_apop_normal_order',
'_apop_search_order', '_apop_search_order',
'_apop_tax_sort_type',
'_apop_normal_order_param', '_apop_normal_order_param',
'_apop_search_order_param', '_apop_search_order_param',
'apop_tax_order_param',
); );
foreach ( $param_settings as $param_setting ) { foreach ( $param_settings as $param_setting ) {
delete_option( $param_setting ); delete_option( $param_setting );
+19 -1
View File
@@ -1,8 +1,13 @@
<?php <?php
/*
* Todo: タクソノミーの通常+カスタムフィールドソート処理の追加
*/
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} // Exit if accessed directly } // Exit if accessed directly
if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) { if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
trait APOP_ORDER_SETTING { trait APOP_ORDER_SETTING {
@@ -81,9 +86,13 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
} }
foreach ( $apop_order_param as $order_col => $orders ) { foreach ( $apop_order_param as $order_col => $orders ) {
if ( $orders['use'] == 1 ) { if ( $orders['use'] == 1 ) {
if ( $order_col == 'custom_field' ) {
$this->set_custom_filed_sort( $orderby, $query, $order_col, $orders, $sort_param );
} else {
$orderby[ $order_col ] = $sort_param[ $orders['sort'] ]; $orderby[ $order_col ] = $sort_param[ $orders['sort'] ];
} }
} }
}
if ( isset( $orderby ) ) { if ( isset( $orderby ) ) {
$query->set( $query->set(
'orderby', $orderby 'orderby', $orderby
@@ -93,11 +102,20 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
$this->set_per_page( $query, 'search' ); $this->set_per_page( $query, 'search' );
} }
private function set_custom_filed_sort( &$orderby, $query, $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 ];
$query->set( 'meta_query', self::get_all_post_args( $meta_key ) );
}
}
private function set_orderby( $query, $id, $target, $order_key ) { private function set_orderby( $query, $id, $target, $order_key ) {
$order_settings = get_option( '_apop_' . $order_key . '_order' ); $order_settings = get_option( '_apop_' . $order_key . '_order' );
if ( isset( $order_settings['target_cat'][ $id ] ) && $order_settings['target_cat'][ $id ] == 1 ) { if ( isset( $order_settings['target_cat'][ $id ] ) && $order_settings['target_cat'][ $id ] == 1 ) {
$sort_meta_key = '_apop_post_' . $target . '_' . $id; $sort_meta_key = '_apop_post_' . $target . '_' . $id;
//$query->set( 'meta_key', $sort_meta_key );
$query->set( 'meta_query', self::get_all_post_args( $sort_meta_key ) ); $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_num' => 'ASC' ) );
$this->set_per_page( $query, self::get_per_page_tag( $target ), $id ); $this->set_per_page( $query, self::get_per_page_tag( $target ), $id );