title: Change posts status to pending based on user role
body: <p>I have members site where users have to pay to subscribe. When user subscribe his role becomes "member" and now can publish to custom post type called "user-profile"</p>
  
  <p>what I want to do is change the status of all published posts to pending in this post type if for example the user role changed to "expired"</p>
  
  <p>I tried this, but doesn't seem to have any effect</p>
  
  <pre><code> function auto_expire_posts(){
      global $wpdb, $wp_roles;
        //get all post ids of published posts.
        $post_ids = $wpdb-&gt;get_results( "SELECT * FROM $wpdb-&gt;posts WHERE post_status = 'publish' ");
  
  foreach($post_ids as $id){
  $postid =  $id-&gt;ID;
  if ($_GET['role'] == "expired" ) 
      {
          $profile_post = array();
          $profile_post['ID'] = $postid;
          $profile_post['post_status'] = 'pending';
          // Update the post into the database
           wp_update_post( $profile_post );
  
         }
  }
  }
  add_action('set_user_role', 'auto_expire_posts');
  </code></pre>