Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • #1015757

    How Can I display related posts by the same author rather than using a tag ?


    Hey TrueCourseCommunications,

    Try adding this to functions.php

    function wpb_related_author_posts($content) {
    if ( is_single() ) { 
        global $authordata, $post;
        $content .= '<h4>Similar Posts by The Author:</h4> ';
        $authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 5 ) );
        $content .= '<ul>';
        foreach ( $authors_posts as $authors_post ) {
            $content .= '<li><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a></li>';
        $content .= '</ul>';
        return $content;
        else { 
        return $content; 

    Best regards,
    Jordan Shannon


    Working. But is there a way to display it the same way as the related posts are displayed. In a grid format using thumbnails



    This should be possible, but will require styling via CSS to match what you need.

    Best regards,
    Jordan Shannon


    I have the css. I just need to know how to place the images in a grid format.




    Thanks for the update, where can we see the results you are getting?

    Best regards,


    I am testing it on the local host. The related-posts template is working fine as you can see on https://recipes.instantpot.com/recipe/french-onion-soup/
    But that is displaying it using tag. I want to use the same template but by using author name rather than tags.



    You need to modify the includes > related-posts.php file for that. Use the same get_posts query as the filter above on line 75.

            $my_query = get_posts(
                                    'tag__in' => $tag_ids,
                                    'post_type' => get_post_type($this_id),
                                    'showposts'=>$postcount, 'ignore_sticky_posts'=>1,
                                    'post__not_in' => array($this_id))

    You will also need to replace $tags (line 58) to get the author info or id instead.

    $tags = get_post_field( 'post_author', $this_id );

    And change the subsequent logic base on the author info.

    Best regards,

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.