• Hello everyone, I hope you are all having a wonderful day.
    I am basically having a problem with a bit of code that should display all of the posts by an author that is listed in a portfolio. Basically I have a a portfolio that lists agents. When you click on any one of them it takes you to a single page about that agent. At the bottom of the page I have a snippet of code that is supposed to list all of the listings by that agent. The problem is that its only listing the posts that I “as the Admin” have posted, lol. I am using get_permalink to get the agent name to use for where it should find the list of posts but like i said, it simply keeps listing my posts. The web addy for the portfolio is http://entechpc.com/agents/ and if you click on any of the agents there you will see that the “All listings by this agent” are the same, they are simply my posts.
    My code snippet to accomplish the on the agent-single.php looks like this

    <?php
    
    $current_author = get_query_var('author');
    
    $author_posts=  get_posts( 'author='.$user->id.'&posts_per_page=-1' );
    
    if($author_posts){
    
    echo "<h2>All listings by this agent</h2>";
    echo '<br />';
    echo '<ol>';
    
    foreach ($author_posts as $author_post)  {
    
     echo '<li><a href="'.get_permalink($author_post->ID).'">'.$author_post->post_title.'</a></li>  ';
    
    }
    
    echo '</ol>';
    
    }
    
    ?>

    So what I am trying to figure out is how to make this snippet of code get the posts only for the person whos name is in the permalink, lol. Is this possible or I am hoping for something that cant be done with wordpress?

    By the way, I will be adding all portfolio items “Agents” My self, so there wont be any other users. So I am trying to make this work without having to have to create accounts and all. The agent listings will be added by me as well so therfore, I cant use anything that would make it pull excerpts from an account id, it has to come from the permalink of the portfolio item or the name of the agent in the portfolio item title or the agent-single.php page or permalink title

  • The topic ‘Problems with listing posts by author’ is closed to new replies.