The Kadence theme is a popular WordPress theme that offers many customization options. One of its options is a related posts section, but it only works on built-in posts. In the article below, I will describe how to add related posts to your custom post type step by step. The article is created with developers in mind.
Kadence Related Content
The Kadenc team previously had a separate plugin called “Kadence Related Content”. I tried using it, but there aren’t many options and it’s probably no longer in development. That’s why I don’t recommend going this route.
Single post customizer option
If you visit customizer settings for Kadence and go to Posts/Pages Layout => Single Post Layout you will find an option called Show Related Posts.

But how to display this section on a custom post type single page? Let’s dive into code. Kadence is displaying the section by including this template template-parts/content/entry_related.php
I need to find an accurate hook to add this template to my custom single CPT view. For my needs, kadence_after_main_content seems to be perfect.
add_action('kadence_after_main_content', function() {
if(is_singular('my-cpt')) {
get_template_part('template-parts/content/entry_related');
}
});
Kadence has a lot of hooks, so find which is best for you.
Get related posts
By default, the related posts query is based on the function get_related_posts_args
. You can check its definition in the file inc/template-functions/single-functions.php. Fortunately, there is a filter to modify WP_Query args:
apply_filters('kadence_related_posts_carousel_args', $args);
So let’s query my custom post type:
add_filter('kadence_related_posts_carousel_args', function($args) {
if(is_singular('my-cpt')) {
$args['post_type'] = 'my-cpt';
$args['post__in'] = get_field('related_products');
unset($args['tax_query']);
}
return $args;
});
In my case, I use ACF to set related posts. Users need to set related posts by themselves. get_field(‘related_products’) is returning an array of post ids.
Modify displayed data
If you need to modify the template for related posts you can copy this to files into your child theme:
- wrapper for related posts => template-parts/content/entry_related.php
- content for single related post => template-parts/content/entry.php
Be careful with entry.php, it’s used by other views, so you can modify for example search result page.
Templates have also some hooks so you are still able to add some data with Kadence Elements.
Conclusion
For those looking to display the related posts section on custom post type single pages, the article demonstrates how to use hooks in Kadence effectively. By adding a custom hook and modifying the related posts query using filters, you can seamlessly integrate this feature into your CPT.
In summary, Kadence is a flexible theme that can be extended to accommodate custom post types and related posts sections, making it a valuable tool for developers looking to enhance their WordPress websites.
Leave a Reply