• Hey everyone. Quick question for you all. This is basically what I’m trying to produce:

    https://code.pitch.net.nz/adm/005/blogs.html

    Is this possible, I’ve a had a Google and Forum search but haven’t found a solution. Basically the authors will be static so I’ll put them into the page manually, but I want to pull each authors latest 3 posts.

    Is there a way to do something like: get_posts where author_id = blah — within WordPress rather than doing a separate SQL query. Or is there a plugin that gives this functionality.

    Thanks in advance for your help.

    Cheers,
    Ben

Viewing 7 replies - 1 through 7 (of 7 total)
  • In order to do this outside of the Loop, you may want to try using multiple query posts: https://codex.www.ads-software.com/Template_Tags/query_posts#Author_Parameters

    Thread Starter ben-lilley

    (@ben-lilley)

    Cool thanks, that looks like it will do the trick. Could I use this multiple times on one page? For example I want to use it 8 times on a page for 8 different authors.

    It depends on where you plan to use this page. Perhaps you better use WP Query since you need 8 of them.

    For example, here’s how you would set it up to show two different author’s pages:

    <?php
    $args = array(
    	'author' => 1,
    	'showposts' => 3,
    	'orderby' => title,
    	'order' => ASC
    	);
    $author1 = new WP_Query($args); ?>
    
    <ul>
    <?php if (have_posts()) : while ($author1->have_posts()) : $author1->the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>
    
    <?php else: endif; ?>
    
    <?php
    rewind_posts();
    $args = array(
    	'author' => 2,
    	'showposts' => 3,
    	'orderby' => title,
    	'order' => ASC
    	);
    $author2 = new WP_Query($args); ?>
    
    <ul>
    <?php if (have_posts()) : while ($author2->have_posts()) : $author2->the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>
    
    <?php else: endif; ?>

    Thread Starter ben-lilley

    (@ben-lilley)

    Thanks for all your help mmuro, I really appreciate it. Unfortunately I’m struggling to get this working, even with your provided code (which was great thanks, explain a few things for me).

    This is the page I’m trying to build – https://code.pitch.net.nz/adm/005/blogs.html – this is being pulled by using category-3.php – There’s 8 people on this blog and for each of them I want to pull their 3 latest posts, the rest of the information is static.

    However if I put your code in, it doesn’t return any results (author id 1 has two posts assigned to it). I’m digging through codex but can’t really find what I want.

    Thanks again for your help.

    The author ID’s you see in that code(1 & 2) are just examples. You should go to the Users list in your admin panel and find out the IDs for each author.

    All you have to do is click on the name and copy the “user_id=” number.

    So, where you see in that array that 'author' => 1, you will change the 1 to whatever numbers you find. Make sense?

    Thread Starter ben-lilley

    (@ben-lilley)

    Yep, I understood the ID bit, both id’s 1 and 2 exist and have posts written by them but it’s still not returning any results. Should that code work right off the bat or do I need to do something else?

    Again, thanks for all the help.

    Thread Starter ben-lilley

    (@ben-lilley)

    <?php
     	$lastposts = get_posts('numberposts=3&amp;author=2');
     	foreach($lastposts as $post) : setup_postdata($post); ?>
    	<li><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>

    Turns out I can do it just like that! I think I was over complicating things. Cheers mate.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘A Bloggers Page (Pull Author Posts)’ is closed to new replies.