WordPress.org

Forums

Query special post in author.php (4 posts)

  1. nickrita
    Member
    Posted 7 years ago #

    In the author profile we habe all his posts as a list. Every author can have his own guestbook by writing a post in category guestbook. Now I want to query the guestbook outside the loop.

    I tried

    <ul>
    <?php
     global $post;
     $myposts = get_posts('category=40');
     foreach($myposts as $post) :
     setup_postdata($post);
     ?>
    <li><a>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
     </ul>

    but with this I get the guestbook-links of all authors in the profile of each author.

    How can I get only the guestbook-post of the current author in the current author's profile?

    Thanks
    Rita

    view profile here: http://www.ci-jou.de/?author=1

  2. Kafkaesqui

    Posted 7 years ago #

    Try:

    <?php
    $author = get_userdata(get_query_var('author'));
    $mypost = new WP_Query('showposts=1&cat=40&author=' . $author->ID);
    if($mypost) : $mypost->the_post();
    ?>
    <ul>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    </ul>
    <?php endif; ?>
  3. nickrita
    Member
    Posted 7 years ago #

    Kafkaesqui, thank you very much, it works!

  4. nickrita
    Member
    Posted 7 years ago #

    Hi, it's me again.

    Is there any chance to get the contend AND the comments of the post together with the title? I tried and was able to get the contend, but not the comments.

    Thanks,
    Rita

Topic Closed

This topic has been closed to new replies.

About this Topic