Simplicityの特徴 › フォーラム › Simplicity2に関する話題何でも › 管理画面での「絞り込み検索」
- このトピックには11件の返信、2人の参加者があり、最後に
technoteにより8年、 4ヶ月前に更新されました。
-
投稿者投稿
-
-
2016年10月29日 11:54 AM #46893
盛土
ゲストテーマと関係なくスミマセン
WP管理画面の投稿一覧で記事を探すとき
日付とカテゴリーで絞り込み検索できるのですが
タグで絞り込み検索できないかと色々と調べているのですが
サイト上で記事を検索するものばかりで・・ -
2016年10月29日 4:41 PM #46899
わいひら
キーマスターここら辺あたりの方法でできるのではないかと思います。
WordPressの投稿一覧でタグのフィルタリングを追加する | Simple Colors
ただ、実際に試したわけではないので、保証はないです。
うまくいかなかった場合に、複雑なカスタマイズはサポート外となるので、何とか自前で行っていただけると助かります。
サポート対象外のもの -
2016年10月29日 5:33 PM #46901
盛土
ゲストできました!!
教えて頂きましたLINK先のコードを
子テーマfunctions.phpにそのままコピペしましたカテゴリーみたいにプルダウンでないのが残念ですが
カテゴリーと組み合わせて検索でき
編集作業が捗り満足してますアドバイス頂きまして
ありがとうございました
m(_ _)m -
2016年10月30日 1:15 AM #46923
technote
ゲスト以下のコードでプルダウンを追加することは可能です。
add_action('restrict_manage_posts', create_function('', <<< EOT global \$post_type, \$tag; if ( is_object_in_taxonomy( \$post_type, 'post_tag' ) ) { \$dropdown_options = array( 'show_option_all' => get_taxonomy( 'post_tag' )->labels->all_items, 'hide_empty' => 0, 'hierarchical' => 1, 'show_count' => 0, 'orderby' => 'name', 'selected' => \$tag, 'name' => 'tag', 'taxonomy' => 'post_tag', 'value_field' => 'slug' ); wp_dropdown_categories( \$dropdown_options ); } EOT ));
-
2016年10月30日 9:04 AM #46927
翔平
ゲストtechnote様
ありがとうございます
見事にプルダウンが表示されました!でも
「すべてのタグ」で検索するとなにもヒットしません
任意のタグで絞り込むとヒットしますつまり
カテゴリーだけでの検索が出来ないようです以上
ご報告まで -
2016年10月30日 9:38 AM #46929
わいひら
キーマスター紹介したカスタマイズを自分でも試したところ、よさげで、次のバージョンでこの機能を実装しようと思っていたので、それ用のコードも載せておきます。
次のバージョンを採用する際には、今回追加したコードは削除したほうがいいかもしれません。//投稿一覧リストの上にタグフィルターを追加する if ( !function_exists( 'add_tag_restrict_filter_on_post_list' ) ): function add_tag_restrict_filter_on_post_list() { global $post_type; if ( is_object_in_taxonomy( $post_type, 'post_tag' ) ) { $tag_name = $_GET && $_GET['tag_name'] ? $_GET['tag_name'] : ''; ?> <?php $tags = get_tags(); if ( $tags ) : ?> <select name="tag_name"> <option value=""<?php echo $tag_name ? '' : ' selected="selected"'; ?>>タグを選択</option> <?php foreach ( $tags as $tag ): ?> <option value="<?php echo $tag->name; ?>"<?php echo $tag_name == $tag->name ? ' selected="selected"' : ''; ?>><?php echo esc_html( $tag->name ); ?> (<?php echo $tag->count; ?>)</option> <?php endforeach; ?> </select> <?php endif; ?> <!-- <input name="tag_name" size="25" value="<?php echo esc_html( $_GET ? $_GET['tag_name'] : '' ); ?>" class="postform" /> --> <?php } } endif; add_action( 'restrict_manage_posts', 'add_tag_restrict_filter_on_post_list' ); //タグネームをタグスラッグに変換する if ( !function_exists( 'convert_tag_name_to_tag_slug' ) ): function convert_tag_name_to_tag_slug() { if ( ! isset( $_GET['post_type'] ) ) { $post_type = 'post'; } elseif ( in_array( $_GET['post_type'], get_post_types( array( 'show_ui' => true ) ) ) ) { $post_type = $_GET['post_type']; } else { wp_die( __('Invalid post type') ); } if ( ! is_object_in_taxonomy( $post_type, 'post_tag' ) || ! isset( $_GET['tag_name'] ) ) { return; } if ( is_array( $_GET['tag_name'] ) ) { $_GET['tag_name'] = implode( ',', $_GET['tag_name'] ); } $tag_name = explode( ',', $_GET['tag_name'] ); $tag_name = array_map( 'trim', $tag_name ); if ( $tag_name ) { $tags = get_tags( 'hide_empty=0&orderby=slug' ); $tags_arr = array(); if ( $tags ) { foreach ( $tags as $tag ) { $tags_arr[$tag->name] = $tag->slug; } } else { unset( $_GET['tag_name'] ); return; } $searh_tags = array(); $matched_tags = array(); foreach ( $tag_name as $t_name ) { if ( isset( $tags_arr[$t_name] ) ) { $searh_tags[] = $tags_arr[$t_name]; $matched_tags[] = $t_name; } } $searh_tags = implode( ' ', $searh_tags ); // OR 検索にしたい場合は、カンマ繋ぎにする // $searh_tags = implode( ',', $searh_tags ); if ( $searh_tags ) { $_GET['tag'] = $searh_tags; $_GET['tag_name'] = implode( ',', $matched_tags ); } else { unset( $_GET['tag_name'] ); } } } endif; add_action( 'load-edit.php', 'convert_tag_name_to_tag_slug' );
-
2016年10月30日 10:51 AM #46931
technote
ゲストタグを選択していない場合の動作を忘れていました。
add_action('load-edit.php', create_function('', <<< EOT if (isset(\$_GET['tag']) && '0' === \$_GET['tag']) { unset (\$_GET['tag']); } EOT ));
ついでに作成者で絞り込むプルダウンも追加してみました。
add_action('restrict_manage_posts', create_function('', <<< EOT global \$post_type, \$tag; if ( is_object_in_taxonomy( \$post_type, 'post_tag' ) ) { \$dropdown_options = array( 'show_option_all' => get_taxonomy( 'post_tag' )->labels->all_items, 'hide_empty' => 0, 'hierarchical' => 1, 'show_count' => 0, 'orderby' => 'name', 'selected' => \$tag, 'name' => 'tag', 'taxonomy' => 'post_tag', 'value_field' => 'slug' ); wp_dropdown_categories( \$dropdown_options ); } wp_dropdown_users( array( 'show_option_all' => 'すべてのユーザー', 'name' => 'author' ) ); EOT ));
-
2016年10月30日 11:00 AM #46932
technote
ゲストわいひら様
プルダウン作成時にvalueにslugを使用すれば、「タグネームをタグスラッグに変換する」処理は必要ありません。//投稿一覧リストの上にタグフィルターを追加する if ( !function_exists( 'add_tag_restrict_filter_on_post_list' ) ): function add_tag_restrict_filter_on_post_list() { global $post_type; if ( is_object_in_taxonomy( $post_type, 'post_tag' ) ) { $_tag = $_GET && $_GET['tag'] ? $_GET['tag'] : ''; ?> <?php $tags = get_tags(); if ( $tags ) : ?> <select name="tag"> <option value=""<?php echo $_tag ? '' : ' selected="selected"'; ?>>タグを選択</option> <?php foreach ( $tags as $tag ): ?> <option value="<?php echo $tag->slug; ?>"<?php echo $_tag == $tag->slug ? ' selected="selected"' : ''; ?>><?php echo esc_html( $tag->name ); ?> (<?php echo $tag->count; ?>)</option> <?php endforeach; ?> </select> <?php endif; ?> <!-- <input name="tag_name" size="25" value="<?php echo esc_html( $_GET ? $_GET['tag_name'] : '' ); ?>" class="postform" /> --> <?php } } endif; add_action( 'restrict_manage_posts', 'add_tag_restrict_filter_on_post_list' );
-
2016年10月30日 11:51 AM #46933
わいひら
キーマスター確かに、僕の書いたのはコピペをただ動くものにしただけなので、なんか二度手間みたいなことになってますね^^;
というか、technoteさんの書かれている方法のほうが、スマートでコードも見やすいので次のバージョンでは、こちらを使わせていただこうと思います。//投稿一覧リストの上にタグフィルターと管理者フィルターを追加する if ( !function_exists( 'custmuize_restrict_manage_posts' ) ): function custmuize_restrict_manage_posts(){ global $post_type, $tag; if ( is_object_in_taxonomy( $post_type, 'post_tag' ) ) { $dropdown_options = array( 'show_option_all' => get_taxonomy( 'post_tag' )->labels->all_items, 'hide_empty' => 0, 'hierarchical' => 1, 'show_count' => 0, 'orderby' => 'name', 'selected' => $tag, 'name' => 'tag', 'taxonomy' => 'post_tag', 'value_field' => 'slug' ); wp_dropdown_categories( $dropdown_options ); } wp_dropdown_users( array( 'show_option_all' => 'すべてのユーザー', 'name' => 'author' ) ); } endif; add_action('restrict_manage_posts', 'custmuize_restrict_manage_posts');
使わせていただきます。ありがとうございます!
-
2016年10月30日 12:04 PM #46934
わいひら
キーマスターあ、「全てのタグ」選択時の処理も書く必要があるのか。
//投稿一覧リストの上にタグフィルターと管理者フィルターを追加する if ( !function_exists( 'custmuize_restrict_manage_posts' ) ): function custmuize_restrict_manage_posts(){ global $post_type, $tag; if ( is_object_in_taxonomy( $post_type, 'post_tag' ) ) { $dropdown_options = array( 'show_option_all' => get_taxonomy( 'post_tag' )->labels->all_items, 'hide_empty' => 0, 'hierarchical' => 1, 'show_count' => 0, 'orderby' => 'name', 'selected' => $tag, 'name' => 'tag', 'taxonomy' => 'post_tag', 'value_field' => 'slug' ); wp_dropdown_categories( $dropdown_options ); } wp_dropdown_users( array( 'show_option_all' => 'すべてのユーザー', 'name' => 'author' ) ); } endif; add_action('restrict_manage_posts', 'custmuize_restrict_manage_posts'); //投稿一覧で「全てのタグ」選択時は$_GET['tag']をセットしない if ( !function_exists( 'custmuize_load_edit_php' ) ): function custmuize_load_edit_php(){ if (isset($_GET['tag']) && '0' === $_GET['tag']) { unset ($_GET['tag']); } } endif; add_action('load-edit.php', 'custmuize_load_edit_php');
-
2016年10月30日 12:30 PM #46935
盛土
ゲストプルダウン実装できました!
(バージョンアップ時には削除します)絞り込み検索上の「投稿を検索」でも
タグを検索できると
良いんですけどねありがとうございました
m(_ _)m -
2016年10月30日 12:33 PM #46936
technote
ゲストわいひら様
対応ありがとうございます。
-
-
投稿者投稿
- トピック「管理画面での「絞り込み検索」」には新しい返信をつけることはできません。