WordPress.org

Ready to get started?Download WordPress

Forums

getting authors posts issue (6 posts)

  1. bayboran
    Member
    Posted 3 years ago #

    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 } ?>

  2. bayboran
    Member
    Posted 3 years ago #

    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?

  3. bayboran
    Member
    Posted 3 years ago #

    <?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.

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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
  5. alchymyth
    Forum Moderator
    Posted 3 years ago #

    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

  6. bayboran
    Member
    Posted 3 years ago #

    sorry for this. i'm new here... ;)

Topic Closed

This topic has been closed to new replies.

About this Topic