Skip to content

How to Show Related Post by Child Category in WordPress?

Key Takeaways

  • Nexter Blocks Post Listing block is the block used to show related posts by child category in WordPress, and it requires Nexter Blocks to be installed and activated.
  • WordPress does not provide a default option for related posts by child category, so the post uses custom code in a Child theme function.php file or plugins like Code Snippets or Nexter Extensions.
  • tpgb_custom_doc_query is the filter key added in the Post Listing block’s Query tab Custom Query ID field after selecting the listing type, post type, style, and layout.
Table of Contents

Related posts matched on a broad parent category are barely related. Everything under Design is not related to everything else under Design.

Matching on the child category instead narrows it to the posts that genuinely share a subject.

Before You Start

  • Edition: Pro — related listings needs Nexter Blocks Pro.
  • Block to enable: Post Listing, switched on under Nexter > Blocks in your WordPress dashboard.
  • A category tree with real child categories, and posts filed in the children rather than only the parent.
  • A single post template to put the block in.

Steps

  1. Edit your single post template and add a Post Listing block.
Adding the related listing
  1. Set the listing type to related.
  1. Set the matching to use category.
  1. Make sure your posts are filed in child categories, not just the parent.
  1. Save and open a real post to check the matches.

How It Behaves

The matching uses the categories actually assigned to the post, and prefers the deepest ones.

  • Matching reads the post’s own terms. A post filed only in a parent category can only ever match on that parent, so the quality of the result is decided when the post is filed.
  • The block skips categories that still have children when it builds the match, which is what makes the result narrow rather than broad.
  • The current post is excluded, as with any related listing.
  • It needs a single post context, so it belongs in a template rather than on an ordinary page — see the related posts guide.
  • Measured with Nexter Blocks Pro deactivated: this stops working. The block still renders a plain list of posts, so there is no error to see — just the feature quietly missing.

Limitations

  • Pro only — measured with Nexter Blocks Pro deactivated, the listing does not follow the current post.
  • It cannot fix bad filing. If posts sit only in parent categories, matching on children has nothing to work with.
  • Narrow matching can return nothing, where broad matching would at least have returned something.
  • A deep category tree is work to maintain, and half-maintained trees produce worse results than a flat set of tags.
  • There is no relevance ranking, so matches come back in the usual order.

Troubleshooting

I get no related posts at all

Narrow matching found nothing. Check your posts are filed in child categories and that more than one post shares each child.

The matches are still too broad

Your posts are filed in the parent. Move them into the appropriate child categories.

It works on some posts and not others

Those posts are filed differently. Matching depends entirely on the terms each post carries.

Should I use tags instead?

Often yes. Tags are usually narrower than categories and produce tighter matches with less structure to maintain.

Related Docs

Share your Thoughts

Still in Doubt? Let’s Assist You

Have Feedback or Questions?

Join our WordPress Community on Facebook!