How to show posts from a specific author

Discussion in 'WordPress' started by mikemdg, Oct 14, 2011.

  1. #1
    I have this script that posts the date of and the 3 most recent blog posts from wordpress, but am wondering how I can modify it to only show posts from a certain author.

    I've tried things like (have_posts('author=2')); etc... but not sure how it works???

    <?php
    /* site_last_updated
    *
    * This will check the modified_date of all published posts and give you the most recent date.
    *
    */
    function site_last_updated($d = '') {
    $recent = new WP_Query("showposts=1&orderby=modified&post_status=publish");
    if ( $recent->have_posts() ) {
    while ( $recent->have_posts() ) {
    $recent->the_post();
    $last_update = get_the_modified_date($d);
    }
    echo $last_update;
    }
    else
    echo 'No posts.';
    }
    ?>

    <?php while (have_posts()): the_post(); ?>
    <?php endwhile; ?>
    <span class="title">The Latest News</span><br/>
    <span class="subtitle">Last Updated: <?php site_last_updated('') ?></span><br/><br/>
    <?php while (have_posts()): the_post(); ?>
    <span class="greensubtitle"><?php the_title(); ?></span>
    <span class="bodytext"><?php the_excerpt(); ?></span>
    <?php endwhile; ?>
     
    mikemdg, Oct 14, 2011 IP
  2. adbox

    adbox Well-Known Member

    Messages:
    906
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    155
    Digital Goods:
    1
    #2
    let me know if this helps:
    http://www.livexp.net/wordpress/how-to-list-wordpress-posts-by-author.html

    It's not making use of the loop, which I believe can be done but I couldn't find out how on a quick search. The above will work though I believe.

    
    $numposts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_author = 1");
    echo "Posts by Author 1";
    
    foreach ($numposts as $numpost) {
    echo $numpost->post_title."<br>";
    echo apply_filters('the_content',  $numpost->post_content);
    }
    
    Code (markup):
     
    adbox, Oct 15, 2011 IP