0

I am looking for a plugin which allows to see posts to particular user group (or role) only, post’s names included. I want to hide even a hint of presents of these posts from everyone except of particular user group (or role).

I already tried lots of popular plugins with promising descriptions and high rating, but, unfortunately, they don’t meet this simple requirement. Most of them allow to hide content only but not the title and category.

1

Actually the same requirement was went through in one of my projects.Me too searched for many plugins and they don't met up with the requirement. so then i found a solution for this with using some plugins

1.you need to install the ultimate member plugin.

2.in the post you need to create a taxonomy

3.using a set of codes in function.php we can able to add taxonomy term as the user's username when a new user is signup. The code given below

<?php add_action( 'user_register', 'yg_user_registration', 10, 1 );
function yg_user_registration( $user_id ) {
$user_info = get_userdata($user_id); $user_name = $user_info->user_login;
wp_insert_term( $user_name, 'user1', array() );
}
add_action( 'delete_user', 'yg_user_delete', 10, 1 );
function yg_user_delete( $user_id ) {
$user_info = get_userdata($user_id); 
$user_name = $user_info->user_login;
wp_delete_term( get_term_by('name', $user_name, 'user1')->term_id,'user1', array() );
}
?>

4.After completing upto this step if a new user is added you will get the users id as taxonomy term then you can assign the the post for any user separately.if you deleted the user the taxonomy term also get deleted

5.now we need to show the post to specific user by getting there id for that follow the below code.

 <?php $author = get_current_user_id(); ?>
<?php $author_obj = get_user_by('id',$author); 
?>
<?php
$custom_args = array('post_type' => 'admin-post',
    'posts_per_page' => '-1',
    'orderby' => 'id',
    'order' => 'ASC',
    'tax_query' => array(array(
            'taxonomy' => 'user1',
            'field' => 'slug',
            'terms' => $author_obj->user_login
        ))
);
$custom_query = get_posts($custom_args);
?>
<?php
foreach ($custom_query as $value) {
    ?>
/*your data */
<?php } ?>

by this set of codes we can achieve the requirement

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.