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 http://www.q8pd.com
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 *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>