Show related posts on your WordPress blog for custom post type

You can use custom post type for special posts on your blog and there are lots of plugins or hacks available to display related posts but those are limited to the general posts only, not for the custom post type.

Say you have created a new post type function for listing your products on your WordPress website or blog. On the product detailed page (single.php) you just prefer to display the other products info which belongs to the same product category.  Now the trick will work.

Assume you have created (registered) a new taxonomy for your product categories as ‘product_categories’from your functions.php file. Now you can use the template code to display the related products (posts) in any place of the page you prefer. It will display latest 4 posts of the same category, no duplicate at all.

You may also like

4 Comments

  1. Hey,

    I have a custom post type “project” as well as the regular post. Each post type has it’s own unique categories. However, when I use the code to display related “projects” on a single project page, I don’t get related projects. I get all posts.

    Any thoughts on why this is happening?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.