WP PLUGIN アーカイブページの投稿表示順設定

・管理画面メニュー(サブメニュー)の修正
・1ページ表示件数の追加
・pre_get_postするクエリの追加
・検索用設定の追加
This commit is contained in:
2021-05-06 21:09:35 +09:00
parent 05b5fa91aa
commit 803c742a9f
8 changed files with 773 additions and 234 deletions
+36 -5
View File
@@ -4,9 +4,12 @@ if ( ! defined( 'ABSPATH' ) ) {
} // Exit if accessed directly
if ( ! class_exists( 'APOP' ) ) {
require_once __DIR__ . '/../util/apop-order-setting.php';
class APOP {
use APOP_ORDER_SETTING;
const TEMPLATE_DIR = __DIR__ . '/../template/';
public function __construct() {
@@ -19,17 +22,25 @@ if ( ! class_exists( 'APOP' ) ) {
'APO +',
'level_8',
'apop_post_sort',
array( $this, 'show_option_page' ),
array( $this, 'display_setting_page' ),
'',
50
);
add_submenu_page(
'apop_post_sort', // parent_slug
'Sort taxonomy', // page_title
'設定', // menu_title
'administrator', // capability
'apop_post_sort', // menu_slug
array( $this, 'display_setting_page' ) // function
);
add_submenu_page(
'apop_post_sort', // parent_slug
'Select taxonomy', // page_title
'タクソノミー選択', // menu_title
'並べ替え', // menu_title
'administrator', // capability
'apop_post_sort_setting', // menu_slug
array( $this, 'display_setting_page' ) // function
array( $this, 'show_option_page' ) // function
);
}
@@ -42,15 +53,14 @@ if ( ! class_exists( 'APOP' ) ) {
$settings = array(
'_apop_cat_order', //カテゴリー設定
'_apop_per_page', //1ページ表示件数
'_apop_tag_order', //タグ設定
'_apop_tax_order', //カスタムタクソノミー設定
);
foreach ( $settings as $setting ) {
$opt = $_POST[ $setting ];
update_option( $setting, $opt );
}
require_once self::TEMPLATE_DIR . 'success.php';
}
@@ -60,6 +70,20 @@ if ( ! class_exists( 'APOP' ) ) {
public function show_option_page() {
//検索の投稿表示順設定
if ( isset( $_POST['_apop_post_search'] ) ) {
check_admin_referer( 'sh_options' );
$this->update_search_sort( 'search' );
require_once self::TEMPLATE_DIR . 'success.php';
}
if ( isset( $_POST['_apop_search_order'] ) ) {
check_admin_referer( 'sh_options' );
update_option( '_apop_search_order', $_POST['_apop_search_order'] );
require_once self::TEMPLATE_DIR . 'success.php';
}
//カテゴリーの投稿表示順設定
if ( isset( $_POST['_apop_post_category'] ) ) {
check_admin_referer( 'sh_options' );
@@ -96,6 +120,13 @@ if ( ! class_exists( 'APOP' ) ) {
}
}
private function update_search_sort() {
$posts_sort = $_POST['_apop_post_search']['post_sort'];
foreach ( $posts_sort as $post_id => $sort ) {
update_post_meta( $post_id, '_apop_post_search', $sort );
}
}
}
}