Jetpack Related Posts and Custom Post Types

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 responses to “Jetpack Related Posts and Custom Post Types”

  1. Hi Mikey!

    Could you may be help me fix the Like buttons on custom post types? Mine don’t work. The button just says ‘loading’ forever. Thanks in advance.

    1. Hi Uma – in order to help, please contact Jetpack Support and give us as much information about the issue as possible: http://jetpack.me/contact-support/

  2. 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' );
    }

    1. Good idea! I’m not sure how much this will help, but it can’t hurt 🙂


Leave a Reply

%d bloggers like this: