Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Get the posts
- $posts_by_author_ID = get_posts( array(
- 'post_type' => 'model'
- ,'post_status' => 'publish'
- ,'orderby' => 'post_author'
- ,'order' => 'DESC'
- ) );
- # >>> DEBUGGING STEP 1
- echo '<h3>THE OUTPUT OF THE POSTS QUERY</h3><pre>';
- print_r( $posts_by_author_ID );
- echo '</pre>';
- # / STEP 1
- foreach ( $posts_by_author_ID as $post )
- {
- static $user;
- $new_user = get_user_by( 'id', $post->post_author );
- # >>> DEBUGGING STEP 2
- echo '<h3>THIS IS ONE OF YOUR USERS</h3><pre>';
- print_r( $new_user );
- echo '</pre>';
- # / STEP 2
- // Let's save some queries
- if (
- isset ( $user )
- AND $user->ID === $new_user->ID
- )
- continue;
- $user = $new_user;
- foreach ( $user->roles as $role )
- {
- $posts_by_author_role[ $role ] = array(
- 'premium-models' => $user
- ,'post' => $post
- );
- }
- }
- // Sort by key a.k.a. role
- ksort( $posts_by_author_ID );
- # >>> DEBUGGING STEP 3
- echo '<h3>THIS IS THE RESULT OF SORTING THE POSTS BY AUTHOR</h3><pre>';
- print_r( $posts_by_author_ID );
- echo '</pre>';
- # / STEP 3
- # >>> DEBUGGING STEP 4
- echo '<pre>'; // Only for debugging/developing - should get deleted when done
- foreach ( $posts_by_author_ID as $role => $data )
- {
- list( $user, $post ) = $data;
- // Now we can output our data
- // The user data is saved inside $user
- // The actual post data is saved inside $data
- // The following is only for debugging/developing - should get deleted when done
- var_export( $user, false );
- var_export( $post, false );
- }
- echo '</pre>'; // Only for debugging/developing - should get deleted when done
- # / STEP 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement