WP PLUGIN 検索のソート設定修正
・検索のソート対象にカスタム投稿を追加
This commit is contained in:
@@ -17,9 +17,8 @@ if ( ! class_exists( 'APOP_UI' ) ) {
|
|||||||
|
|
||||||
public static function get_all_search_normal_posts( $key ) {
|
public static function get_all_search_normal_posts( $key ) {
|
||||||
$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, $key );
|
||||||
$posts_data = get_posts( $args );
|
$posts_data = get_posts( $args );
|
||||||
$list = array();
|
|
||||||
foreach ( $posts_data as $i => $post_data ) {
|
foreach ( $posts_data as $i => $post_data ) {
|
||||||
$order = $i + 1;
|
$order = $i + 1;
|
||||||
$no_order = self::is_sort_post_registered( $post_data->ID, $meta_key ) ? '' : ' no-order';
|
$no_order = self::is_sort_post_registered( $post_data->ID, $meta_key ) ? '' : ' no-order';
|
||||||
@@ -32,8 +31,20 @@ if ( ! class_exists( 'APOP_UI' ) ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function create_search_normal_args( $meta_key ): array {
|
private static function create_search_normal_args( $meta_key, $key = 'normal' ): array {
|
||||||
|
$post_type = array( 'post' );
|
||||||
|
if ( $key == 'search' ) {
|
||||||
|
$add_post_type = array_values( get_post_types( array(
|
||||||
|
'public' => true,
|
||||||
|
'_builtin' => false,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$post_type = array_merge( $post_type, $add_post_type );
|
||||||
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
'post_type' => $post_type,
|
||||||
'post_status' => array( 'publish', 'draft' ),
|
'post_status' => array( 'publish', 'draft' ),
|
||||||
'posts_per_page' => - 1,
|
'posts_per_page' => - 1,
|
||||||
'orderby' => 'meta_value_num',
|
'orderby' => 'meta_value_num',
|
||||||
|
|||||||
Reference in New Issue
Block a user