title: Wordpress, redirect a user directly to a custom post edit screen after login
body: <p>currently I got this:</p>
  
  <pre><code>function redirect_companies()
  {
      if ( current_user_can( 'ca_company' ) )
      {
          $screen = get_current_screen();
  
          if ( $screen-&gt;post_type != 'unternehmen' &amp;&amp; $screen-&gt;id != 'profile' )
          {
              global $current_user;
  
              $current_users_posts = get_posts(
                                          array(
                                              'post_type' =&gt; 'unternehmen',
                                              'author' =&gt; $current_user-&gt;ID
                                          )
                                      );
  
              if ( count( $current_users_posts ) &gt; 1 )
              {
                  $redirect = admin_url( 'edit.php?post_type=unternehmen' );
              }
              else
              {
                  $redirect = get_edit_post_link( $current_users_posts[0]-&gt;ID );
              }
  
              wp_redirect( $redirect, 301 );
          }
      }
  }
  add_action('current_screen', 'redirect_companies');
  </code></pre>
  
  <p>What it should do: A user with role 'ca_company' logs into wordpress backend and instantly gets redirected to either the overview screen of the custom post type posts of "unternehmen" or, if only one post by this user exists, to the edit screen of that one post.</p>
  
  <p>Also, it should perform this redirect routine, if the user is trying to access any page that is not from post type "unternehmen" and is not the user-profile-edit screen.</p>
  
  <p>I successfully tested this when I already was logged in as auch user and then trying to access for example the dashboard. This works.</p>
  
  <p>But if I completely log out of WP and then log in again, wordpress is performing this:</p>
  
  <p><a href="http://i.stack.imgur.com/M60aJ.png" rel="nofollow">http://i.stack.imgur.com/M60aJ.png</a></p>
  
  <p>... and then my browser is telling me, that there is a redirecting error. Infinite redirecting loop. But why? Why does it even go into that "if" where I check for post type "unternehmen". Because if I log in, I am first getting to dashboard...</p>
  
  <p>Hope someone can help :)</p>