• I’m hacking around with a complicated configuration that involves custom post types and custom taxonomies in a multi-author environment (but not WPMU).

    I am creating an archive template for the custom post type, and I want to set it up so that if an author has created more than one post, it should only show the oldest one.

    My current loop looks like this

    $args = array
    	('post_type' => 'ticketlisting',
    		'posts_per_page' => 50,
    		'tax_query' => array
    		(array
    			(
    			'taxonomy' => 'tier',
    			'field' => 'slug',
    			'terms' => 'goldstar'
    			)
    		)
    	);
    
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    	the_title();
    	echo '<div class="entry-content">';
    	$post_id = get_the_ID();
    	/* show post content here */
    	echo '</div>';
    endwhile;
Viewing 4 replies - 1 through 4 (of 4 total)
  • $args= array(
    	'orderby' => 'date',
    	'order' => 'ASC',
    	'posts_per_page' => 1
    );
    Thread Starter adamrice

    (@adamrice)

    Thanks.

    Will that get me the oldest post from each author, or just the oldest post from among all authors? I want to do the former, but it looks like it does the latter.

    $authors = $wpdb->get_results("SELECT ID, user_nicename, display_name from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");
    foreach($authors as $author){
    	$numposts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_author = " . $author->ID . " ORDER BY post_date ASC LIMIT 1 ");
    	echo '<ul>';
    	echo '<li>Author: ' . $author->display_name . '</li>';
    	foreach ($numposts as $numpost) {
    		echo '<li>Oldest Post: '.$numpost->post_title.'</li>';
    	}
    	echo '</ul>';
    }
    Thread Starter adamrice

    (@adamrice)

    Awesome, thanks. I’ll try to combine that with my other finicky selection criteria.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show only oldest post by author’ is closed to new replies.