Forums

[resolved] query post to diferents role users (6 posts)

  1. joasssko
    Member
    Posted 6 months ago #

    Is it possible to show different posts to a diferent role users?? I need something like this

    User A logged in => Post A ||

    User B logged in => Post B

    I can't use UserID, because there will be a lot of users. I was thinking something like this

    <?php
    if ( is_userA_logged_in() ) {
        echo 'Welcome A user!'; //here comes the query
    } elseif ( is_userB_logged_in() ) {
        echo 'Welcome B user!'; // here comes the query
    }
    ?>

    I was reading on the codex but I only found the is_admin(), how can I call the new role i've created?

    I'd create the new roles in the functions.php with

    <?php
        add_role('userA', 'User A', array(
        'read' => true, // True allows that capability
        'edit_posts' => false,
        'delete_posts' => false, // Use false to explicitly deny
    ));?>
  2. lerizzle
    Member
    Posted 6 months ago #

  3. joasssko
    Member
    Posted 6 months ago #

    thnkz lerizzle for your answer, but that solution only show me how to get the user role or query the role capabilities, but what i need is query 2 diferent posts to and show them to a 2 different users.

  4. keesiemeijer
    moderator
    Posted 6 months ago #

    Did you look here: http://codex.wordpress.org/Function_Reference/current_user_can

    example:

    if(current_user_can('userA')){
    //do stuff
    }
  5. joasssko
    Member
    Posted 6 months ago #

    thnkz keesiemeijer, that works fine for me, now i dont need to query post, i just need to add a coupple of custom_fields and do what i want

  6. keesiemeijer
    moderator
    Posted 6 months ago #

    No problem. Glad you got it resolved.

Reply

You must log in to post.

About this Topic