1

だから、私がやろうとしているのは、WordPress ダッシュボードの投稿のリスト (私のものは実際にはカスタム投稿タイプです) を ID でフィルタリングすることです。

別の領域 (カスタム ウィジェット) をチェックして、ユーザーが特定の投稿を編集できるかどうかを確認しています (WordPress の役割を意図的に回避しているなどではありません)。編集できない場合は、その投稿をリストから除外/除外します。

このリストを取りたい:

画像を参照してください: https://lh6.googleusercontent.com/-nQLDUpoHUig/T84sUXwqNDI/AAAAAAAAB1o/fzZvCkSjawI/w678-h533-k/list_of_posts.PNG

...そして、別の関数が返す投稿 ID を除外します

4

1 に答える 1

2

さて、私は自分の質問に答えました。ここに私がそれをした方法に関するいくつかのコードがあります。

function exclude_list_per_function( $query ) {

    global $wpdb;

    //gets all the post ID's, I know this is a bit of a hack
    $querystr = "
        SELECT $wpdb->posts.ID
        FROM $wpdb->posts
    "; $post_ids = $wpdb->get_results($querystr, OBJECT);

        //Go through each post and pass it to a function that returns true if the user_can, and false if the user_can't
        foreach($post_ids as $post_obj){
            if(!can_user_other_function_view_this_post(get_post($post_obj->ID))){
                //if they_can't, add them to the array to be excluded
                $posts_not_in[]=$post_obj->ID;
            }
        }

        //Set those posts to be excluded from the list.
        $query->set( 'post__not_in', $posts_not_in );
}

add_action( 'pre_get_posts', 'exclude_list_per_function');
于 2012-06-05T18:32:19.193 に答える