Jetpack Related Posts and Custom Post Types

There is not much documentation out there about adding Jetpack’s Related Posts to your own Custom Post Types, so I thought I’d share how to do it!

function allow_my_post_types($allowed_post_types) {
    $allowed_post_types[] = 'your-post-type';
    return $allowed_post_types;
}
add_filter( 'rest_api_allowed_post_types', 'allow_my_post_types' );

Once you’ve replaced your-post-type with your Custom Post Type and added that snippet of code to your themes functions.php, make sure to Reindex your Posts through Jetpack for the changes to work.

I can see this being really useful if you have Products, a Portfolio, or even Events on your site.

4 Replies to “Jetpack Related Posts and Custom Post Types”

  1. Hey Mikey, Great post – this will be really useful – should I not play safe and write it this way:


    if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'related-posts' ) ) {
    function allow_my_post_types($allowed_post_types) {
    $allowed_post_types[] = 'your-post-type';
    return $allowed_post_types;
    }
    add_filter( 'rest_api_allowed_post_types', 'allow_my_post_types' );
    }

Leave a Reply