WP PLUGIN 投稿表示順設定
・タクソノミーのソート順登録/未登録両方取得するようget_postsのパラメータを修正 ・タクソノミーのソート順登録/未登録両方取得に伴いテンプレートを修正 ・通常と検索のソート順登録/未登録両方取得するようget_postsのパラメータを修正 ・「表示設定に従う」メニューへposts_per_pageの設定件数を表示 ・バグ修正:検索設定のnema属性修正と検索ページのメソッド引数修正
This commit is contained in:
+92
-86
@@ -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 = [
|
||||
'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;
|
||||
}
|
||||
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 get_posts( $args );
|
||||
return implode( PHP_EOL, $list );
|
||||
}
|
||||
|
||||
private static function crate_non_registerd_mark( $no_order ) {
|
||||
if ( ! empty( $no_order ) ) {
|
||||
return '■';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private static function create_search_normal_args( $meta_key ): array {
|
||||
return array(
|
||||
'post_status' => array( 'publish', 'draft' ),
|
||||
'posts_per_page' => - 1,
|
||||
'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 );
|
||||
$list = [];
|
||||
$sort_num = 0;
|
||||
foreach ( $target_posts as $key => $target_post ) {
|
||||
$sort_num = $key + 1;
|
||||
$exclude_posts[] = $target_post->ID;
|
||||
$list[] = '
|
||||
<li class="product-list"><span class="sort-num-label">' . $sort_num . '</span>' . get_the_title( $target_post->ID ) . '
|
||||
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 = [];
|
||||
foreach ( $return_data['data'] as $key => $target_post ) {
|
||||
$sort_num = $key + 1;
|
||||
$no_order = self::is_sort_post_registered( $target_post->ID, $return_data['meta_key'] ) ? '' : ' no_order';
|
||||
$list[] = '
|
||||
<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">■
|
||||
<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>
|
||||
|
||||
<label><input class="' . $name_key . '" type="radio"
|
||||
name="_' . $name_key . '[' . $target_key . '][sort]"
|
||||
value="1"' . self::set_search_normal_checked( $sort, 1 ) . '>昇順</label>
|
||||
|
||||
|
||||
<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">■の項目は未登録項目です。ドラッグして並び順を変更後に「変更を保存」をクリックしてください。</div>';
|
||||
public static function none_registered_alert_msg(): string {
|
||||
return '<div class="no_registered_exp">■は未登録項目です。ドラッグして並び順を変更後に「変更を保存」をクリックしてください。</div>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user