function exclude_posts_by_user_role($query) {
if (!is_admin() && $query->is_main_query() && (is_home() || is_archive())) {
$excluded_posts = array();

if (current_user_can('subscriber')) {
$excluded_posts = array(1, 2, 3);
}
if (current_user_can('contributor')) {
$excluded_posts = array_merge($excluded_posts, array(4, 5, 6));
}


$query->set('post__not_in', $excluded_posts);
}
}
add_action('pre_get_posts', 'exclude_posts_by_user_role');


blogların listelendiği sayfa için bu kodları incele mantığını kavrarsın. Bunu function php ye ekleyebilirsin.



$excluded_posts = array();

if (current_user_can('subscriber')) {
$excluded_posts = array(1, 2, 3);
} elseif (current_user_can('contributor')) {
$excluded_posts = array(4, 5, 6);
}

if (in_array(get_the_ID(), $excluded_posts)) {
echo '<p>Bu içerik sizin rolünüz için görüntülenemez.</p>';
} else {
the_content();
}



buda single php için