One author per post – got it working but cant organise into categories :(
-
Got this code ive been working on (grabbed bits from different places)
What it does is posts articles one per author.
Though now im having problems pulling posts from specific categories,<?php function the_last_post_per_user(){ global $wpdb; $the_authors = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status='publish' AND post_type='post' AND post_author !='1' ORDER BY post_date DESC LIMIT 0, 5"); return $the_authors; } //get all users, iterate through users, query for one post for the user, //if there is a post then display the post title, author, content info $blogusers = the_last_post_per_user(); if ($blogusers) { foreach ($blogusers as $bloguser) { $args = array( 'author' => $bloguser->post_author, 'showposts' => 1, 'caller_get_posts' => 1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { // $user = get_userdata($bloguser->user_id); // echo 'This is one post for author with User ID: ' . $user->ID . ' ' . $user->user_firstname . ' ' . $user->user_lastname; while ($my_query->have_posts()) : $my_query->the_post(); ?> <ul> <li> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <small> Source: <a href="<?php the_syndication_source_link(); ?>"><?php the_syndication_source(); ?></a><br /> <?php the_time('F jS, Y');?> <br /> <?php the_tags('Location: '); ?> </small> </li> </ul> <?php endwhile; } } } ?>
i tried using to get the categories working with it aswell but it doesnt seem to work ??
LEFT JOIN $wpdb->postmeta wpostmeta ON wposts.ID = wpostmeta.post_id LEFT JOIN $wpdb->term_relationships ON (wposts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘One author per post – got it working but cant organise into categories :(’ is closed to new replies.