Related listings by parent categories

Hi HivePress community,

I’m looking to improve how “Related Listings” work on my site.

Currently, HivePress displays related listings based on the most specific (child) category of a listing. The problem is that in many cases, these subcategories contain very few listings (sometimes only one), which results in no related listings being shown at all.

What I would like to achieve instead:

  • If a listing belongs to a subcategory, the related listings should be pulled from its parent (main) category.

  • This way, even if the subcategory is small, users will still see relevant listings from the broader category.

Example:

  • Listing category: Cars → Classic Cars → 1980s

  • Current behavior: shows related only from “1980s” (often empty)

  • Desired behavior: show listings from “Classic Cars” (parent category)

My questions:

  1. Is there a built-in way in HivePress to change this behavior?

  2. If not, what would be the best way to override the related listings query?

  3. Has anyone implemented a fallback logic like:

    • try subcategory

    • if empty → use parent category

Any guidance or code examples would be greatly appreciated.

Thanks in advance!

Thanks for your message — our team will reply shortly.

In the meantime, you can also get instant help from our AI Assistant, familiar with all the docs and solutions we’ve shared over the years.

Hi,

There’s no built-in feature for this at the moment, but if you’re familiar with coding, we can provide some guidance.

You can use the hivepress/v1/models/listing/relate hook to modify the related listings query. To get the parent categories, you can use the WordPress function get_ancestors. This should allow you to customize the related listings logic to include listings from parent categories as well.

Hope this helps