• Resolved robvdn

    (@robvdn)


    Trying to get a list with all posts made by one author to post on their overview page, but somehow what I have so far doesn’t work.

    Can someone help me please?

    $numposts = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_author = $user->id ORDER BY post_date DESC ");
    
    var_dump($numposts);
    
    echo "Mijn dagboek berichten";
    
    echo "<ul>";
    foreach ($numposts as $numpost)  {
    echo "<li>".$numpost->post_title."</li>";
    }
    echo "</ul>";
Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try it with something like this:

    <?php
    $author_posts=  get_posts( 'author=1' ); // author ID = 1
    if($author_posts){
    echo "Mijn dagboek berichten";
    echo '<ul>';
    foreach ($author_posts as $author_post)  {
     echo "<li>".$author_post->post_title."</li>";
    }
    echo '</ul>';
    }
    ?>

    Change the author ID to your ID.

    Thread Starter robvdn

    (@robvdn)

    @keesiemeijer: close but no cigar yet, but thanks for thinking with me 😉

    what I need is a list of posts made by a specific member on their personal member page, meaning the author=1 shouldn’t be static but depending on the member on who’s page you are.

    Maybe this explains:
    Used this code to show the latest post by that specific member:

    <?php
    $info=mysql_query("SELECT post_content FROM wp_posts WHERE post_author = $user->id ORDER BY post_date DESC LIMIT 1");
    $post_title = mysql_fetch_array( $post_title , MYSQL_NUM);
    $array_content = mysql_fetch_array( $info , MYSQL_NUM );
    echo $array_content[0];
    ?>

    Moderator keesiemeijer

    (@keesiemeijer)

    try it with:

    <?php
    $current_author = get_query_var('author');
    $author_posts=  get_posts( 'author='.$current_author );
    if($author_posts){
    echo "Mijn dagboek berichten";
    echo '<ul>';
    foreach ($author_posts as $author_post)  {
     echo "<li>".$author_post->post_title."</li>";
    }
    echo '</ul>';
    }
    ?>
    Thread Starter robvdn

    (@robvdn)

    @keesiemeijer; Thanks that gave me the right direction 🙂
    really appreciate your help here!

    changed the $current_author (line 3) into $user->id and that gave the wanted result 🙂

    Now I have 2 requests left (yes I know I haven’t been clear from the start and I apologize for that):
    1. each title should be linked to the article
    2. the output list should be unlimited in amount, not just the last 5 like now. If that member made 500 posts it should show all 500 with links.

    <?php
    $current_author = get_query_var('author');
    $author_posts=  get_posts( 'author='.$user->id );
    if($author_posts){
    echo "Mijn dagboek berichten";
    echo '<ul>';
    foreach ($author_posts as $author_post)  {
     echo "<li>".$author_post->post_title."</li>";
    }
    echo '</ul>';
    }
    ?>
    Moderator keesiemeijer

    (@keesiemeijer)

    changed the $current_author (line 3) into $user->id

    Where do you set the user->ID?

    Try it with this:

    <?php
    $current_author = get_query_var('author');
    $author_posts=  get_posts( 'author='.$current_author.'&posts_per_page=-1' );
    if($author_posts){
    echo "Mijn dagboek berichten";
    echo '<ul>';
    foreach ($author_posts as $author_post)  {
     echo '<li><a href="'.get_permalink($author_post->ID).'">'.$author_post->post_title.'</a></li>';
    }
    echo '</ul>';
    }
    ?>

    Thread Starter robvdn

    (@robvdn)

    THANK YOU SO MUCH!

    that worked with a small adjustment (line 3 $current_author to $user->id).

    <?php
    $current_author = get_query_var('author');
    $author_posts=  get_posts( 'author='.$user->id.'&posts_per_page=-1' );
    if($author_posts){
    echo "Mijn dagboek berichten";
    echo '<ul>';
    foreach ($author_posts as $author_post)  {
     echo '<li><a href="'.get_permalink($author_post->ID).'">'.$author_post->post_title.'</a></li>';
    }
    echo '</ul>';
    }
    ?>

    I owe you a beer!

    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome. Glad you got it resolved.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘List of all posts by author’ is closed to new replies.