Advertisement
Guest User

Untitled

a guest
Jul 4th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <?php
  2. // Get the posts
  3. $posts_by_author_ID = get_posts( array(
  4.      'post_type'   => 'model'
  5.     ,'post_status' => 'publish'
  6.     ,'orderby'     => 'post_author'
  7.     ,'order'       => 'DESC'
  8. ) );
  9. # >>> DEBUGGING STEP 1
  10. echo '<h3>THE OUTPUT OF THE POSTS QUERY</h3><pre>';
  11. print_r( $posts_by_author_ID );
  12. echo '</pre>';
  13. # / STEP 1
  14.  
  15. foreach ( $posts_by_author_ID as $post )
  16. {
  17.     static $user;
  18.  
  19.     $new_user = get_user_by( 'id', $post->post_author );
  20.  
  21. # >>> DEBUGGING STEP 2
  22. echo '<h3>THIS IS ONE OF YOUR USERS</h3><pre>';
  23. print_r( $new_user );
  24. echo '</pre>';
  25. # / STEP 2
  26.  
  27.     // Let's save some queries
  28.     if (
  29.         isset ( $user )
  30.         AND $user->ID === $new_user->ID
  31.     )
  32.         continue;
  33.  
  34.     $user = $new_user;
  35.  
  36.     foreach ( $user->roles as $role )
  37.     {
  38.         $posts_by_author_role[ $role ] = array(
  39.              'premium-models' => $user
  40.             ,'post' => $post
  41.         );
  42.     }
  43. }
  44. // Sort by key a.k.a. role
  45. ksort( $posts_by_author_ID );
  46.  
  47. # >>> DEBUGGING STEP 3
  48. echo '<h3>THIS IS THE RESULT OF SORTING THE POSTS BY AUTHOR</h3><pre>';
  49. print_r( $posts_by_author_ID );
  50. echo '</pre>';
  51. # / STEP 3
  52.  
  53. # >>> DEBUGGING STEP 4
  54. echo '<pre>'; // Only for debugging/developing - should get deleted when done
  55. foreach ( $posts_by_author_ID as $role => $data )
  56. {
  57.     list( $user, $post ) = $data;
  58.     // Now we can output our data
  59.     // The user data is saved inside $user
  60.     // The actual post data is saved inside $data
  61.  
  62.     // The following is only for debugging/developing - should get deleted when done
  63.     var_export( $user, false );
  64.     var_export( $post, false );
  65. }
  66. echo '</pre>'; // Only for debugging/developing - should get deleted when done
  67. # / STEP 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement