Much too often, we see a ‘Related posts’ section after reading an article. However, there is no built-in widget/function to get these in WordPress. Many blogs implement their own way to get these or use a plugin to do it, most often finding posts from the same category and with the same tags.
For those interested in building their own ‘Related posts’ section, here is my code:
It’s a simple piece of code that finds 4 posts that have at least one category OR at least one tag in common with the current post. You might find it useful to put this code in a function in your functions.php file or, even better, in a template part.
Leave a comment if you any questions or suggestions.
You can also find this code on Codesnippit