Related Posts WordPress Function

Ever wanted to know how you can generate related posts with a function?

Here’s the code for a related posts based on tags and categories; fully commented.

Copy and paste the function into your theme’s functions.php then call it in your loop or anywhere else like this:

echo getRelatedPosts($postID);

Replace $postID with the post ID of the post you want; or use the_ID(); in the loop.

This is verified and used on
If you want to know more, leave a comment and ask! Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *