プラグインCustom Post Type UIのcptui_no_taxonomies_listingフィルタの使用方法・解説

概要

cptui_no_taxonomies_listing フィルタは、WordPress プラグイン「Custom Post Type UI」において、カスタム投稿タイプの管理に関連する税onomiesのリストを変更するために使用されます。このフィルタを利用することで、投稿タイプに関連付けられた税onomiesを制御することが可能です。具体的には、以下のような機能を実装する際によく使われます。

  1. 特定のカスタム投稿タイプから税onomiesを隠す
  2. 外部カスタム税onomiesを追加する
  3. 複数のカスタム投稿タイプでの税onomiesの管理を容易にする
  4. 特定の条件下での税onomiesの選択肢を制限する
  5. プラグイン内部での税onomiesの整合性を保つ
  6. 他のプラグインと連携した柔軟なカスタム投稿管理を行う

このフィルタは、Custom Post Type UI バージョン 1.0.0 以降および、WordPress バージョン 4.0 以降で使用可能です。

構文

add_filter( 'cptui_no_taxonomies_listing', 'your_function_name' );

パラメータ

  • $taxonomies: 税onomiesのリスト(配列)

戻り値

  • フィルタ後の税onomiesのリスト(配列)

サンプルコード

サンプルコード1: 特定のカスタム投稿タイプから特定のような税onomiesを削除する

add_filter( 'cptui_no_taxonomies_listing', function( $taxonomies ) {
    if ( 'your_custom_post_type' === get_post_type() ) {
        $taxonomies = array_diff( $taxonomies, array( 'taxonomy_to_remove' ) );
    }
    return $taxonomies;
});

このコードは、特定のカスタム投稿タイプから特定の税onomiesを削除します。

サンプルコード2: 新たなカスタム税onomiesを追加する

add_filter( 'cptui_no_taxonomies_listing', function( $taxonomies ) {
    $taxonomies[] = 'new_custom_taxonomy';
    return $taxonomies;
});

このコードは、既存の税onomiesに新たなカスタム税onomiesを追加します。

サンプルコード3: 条件に応じて税onomiesを変更する

add_filter( 'cptui_no_taxonomies_listing', function( $taxonomies ) {
    if ( is_user_logged_in() ) {
        $taxonomies[] = 'restricted_taxonomy';
    }
    return $taxonomies;
});

このコードは、ユーザーがログインしている場合のみ特定の税onomiesを追加します。

サンプルコード4: 複数のカスタム投稿タイプで税onomiesのリストを調整する

add_filter( 'cptui_no_taxonomies_listing', function( $taxonomies ) {
    $post_types = array( 'post_type_one', 'post_type_two' );
    if ( in_array( get_post_type(), $post_types ) ) {
        $taxonomies[] = 'common_taxonomy';
    }
    return $taxonomies;
});

このコードは、特定のカスタム投稿タイプで共通の税onomiesを追加します。

サンプルコード5: フィルタのデバッグ情報を表示する

add_filter( 'cptui_no_taxonomies_listing', function( $taxonomies ) {
    error_log( print_r( $taxonomies, true ) );
    return $taxonomies;
});

このコードは、税onomiesのリストをデバッグするためにエラーログに出力します。

この関数のアクションでの使用可能性

アクション 使用例
mu_plugin_loaded
registered_post_type
plugins_loaded
wp_roles_init
setup_theme
after_setup_theme
set_current_user
init
register_sidebar
wp_loaded
send_headers
parse_query
pre_get_posts
wp
template_redirect
get_header
wp_head

この表では、cptui_no_taxonomies_listing フィルタがどのアクションで使用可能かを示しています。

この関数について質問する


上の計算式の答えを入力してください