サポート » 使い方全般 » 他ユーザーの記事を表示させないが、管理者は全て閲覧可能にしたい

  • http://www.warna.info/archives/2557/

    こちらのサイトで、他ユーザーの記事を表示させないようにしましたが、
    管理者で確認すると、下書きと非表示は表示されません。

    どうにか表示させる事はできないでしょうか?

    function exclude_other_posts( $wp_query ) {
        if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) {
            $post_type = get_post_type_object( $_REQUEST['post_type'] );
            $cap_type = $post_type->cap->edit_other_posts;
        } else {
            $cap_type = 'edit_others_posts';
        }
    
        if ( is_admin() && $wp_query->is_main_query() && ! $wp_query->get( 'author' ) && ! current_user_can( $cap_type ) ) {
            $user = wp_get_current_user();
            $wp_query->set( 'author', $user->ID );
        }
    }
    add_action( 'pre_get_posts', 'exclude_other_posts' );
  • トピック「他ユーザーの記事を表示させないが、管理者は全て閲覧可能にしたい」には新たに返信することはできません。