relatedpostslistinfrontend

Show WordPress Related Posts With Taxonomy and a Custom Post Type

Final product image
What You’ll Be Creating

Sometimes you want your blog posts to appear on more pages in your WordPress site than just your blog.

You’ve already got the option of using category and taxonomy archives, as well as tags. This can help you divide up your content and add a variety of sections to your blog or news site.

But sometimes you might have posts that relate to a custom post type. A good example of this is a store. The products in your store are custom post types, and in order to help you sell those products, you might write blog posts about them.

In this tutorial, I’ll show you how to add a list of relevant posts to each page for a custom post type in your site. I’ll do this using a custom taxonomy, whose terms will correspond to the names of those products you want to write posts about. I’ll show you how to assign the custom taxonomy to both products and standard posts, and use that relationship to output a list of posts on the single page for the product.

What You’ll Need

To follow along with this tutorial, you’ll need:

  • A development installation of WordPress—don’t add anything to your live site until you have it working!
  • A code editor.
  • A theme you can edit directly or one with an action hook after the content. If you’re using a third-party theme without hooks, you’ll need to create a child theme and edit that.

Setting Up the Plugin

Start by creating a new plugin and adding the header information to it:

Powered by WPeMatico

Leave a Comment

Scroll to Top