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.


Posted

in

by

Tags:

Comments

4 responses to “Show related posts on your WordPress blog for custom post type”

  1. WordPress Theme Developer in the Philippines avatar

    This is a very detailed instruction for showing related post in WordPress. I was just looking for some information about this stuff and end up reading your blog. Thank you for sharing!

  2. Guest avatar
    Guest

    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?

  3. Razu avatar
    Razu

    Thank you so much for the fantastic snippet and tutorial

Leave a Reply

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