Support » Fixing WordPress » getting authors posts issue

  • i want to get last authors 3 posts at my home page. only author posts as level=4. here are my codes but it doesn’t get the post. there is no result when run the codes. is there any idea?

    <?php $authors = get_users_of_blog(); ?>
    <?php
    $latest_posts = array();
    foreach ( $authors as $author ) {
    $user = new WP_User( $author->ID );
    if ($user->has_cap(‘level_4’))
    continue;
    $ps = get_posts(‘numberposts=3&post_type=post&author=’ . $author->ID);
    foreach ($ps as $p) {
    $latest_posts[$p->post_date] = $p;
    }
    }
    krsort($latest_posts);
    ?>
    <?php
    $counter =0;
    foreach ($latest_posts as $post) {
    $counter++;
    if ($counter > 3)
    break;
    setup_postdata($post);
    ?>
    <div class=”yazar_alan”>
    <div style=”float:left; padding-right:10px;”>
    <?php userphoto_the_author_thumbnail(); ?>
    </div>
    <div style=”float:left;”>
    <div class=”yazi_baslik”>” class=”siyah_renk”><?php the_title(); ?></div>
    <div class=”yazar_adi”>” class=”siyah_renk ver11″><?php the_author_meta(‘first_name’); ?> <?php the_author_meta(‘last_name’); ?></div>
    </div>
    </div>
    <?php } ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • and sorry for all.

    NOT : $ps = get_posts(‘numberposts=3&post_type=post&author=’ . $author->ID);

    TRUE: $ps = get_posts(‘numberposts=1&post_type=post&author=’ . $author->ID);

    why those codes doesn’t run?

    <?php $authors = get_users_of_blog(); ?>

    <?php
    $latest_posts = array();
    foreach ( $authors as $author ) {
    $user = new WP_User( $author->ID );
    if ($user->has_cap(‘level_10’))
    continue;
    $ps = get_posts(‘numberposts=1&post_type=post&author=’ . $author->ID);
    foreach ($ps as $p) {
    $latest_posts[$p->post_date] = $p;
    }
    }
    krsort($latest_posts);
    ?>

    <?php
    $counter =0;
    foreach ($latest_posts as $post) {
    $counter++;
    if ($counter > 3)
    break;
    setup_postdata($post);
    ?>

    <div class=”yazar_alan”>
    <div style=”float:left; padding-right:10px;”>
    <?php userphoto_the_author_thumbnail(); ?>
    </div>
    <div style=”float:left;”>
    <div class=”yazi_baslik”>” class=”siyah_renk”><?php the_title(); ?></div>
    <div class=”yazar_adi”>” class=”siyah_renk ver11″><?php the_author_meta(‘first_name’); ?> <?php the_author_meta(‘last_name’); ?></div>
    </div>
    </div>
    <?php } ?>

    this is the solution… you can get last 3 author posts with these codes.

    if you use the code button, or post between backtics (under the esc key on an american keyboard, same key as ~) it will keep your code from being messed up on here

    it will look like this
    and not get parsed
    much easier to read
    and you don't lose any code

    Michael

    (@alchymyth)

    Forum Moderator

    to mark code in this forum, press the ‘code’ buttom once, then paste the code, then press the ‘code’ button again;

    or:
    paste the code, hightlight the code, then press the ‘code’ button.

    ps:
    you can edit each of your replies for up to 30 minutes after presssing the ‘post’ button; and for instance fix the code markup

    sorry for this. i’m new here… 😉

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘getting authors posts issue’ is closed to new replies.