Skip to content

Instantly share code, notes, and snippets.

@BinaryMoon
Last active December 2, 2019 06:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BinaryMoon/cca23cdb72a9ce42a0460e8d881ff021 to your computer and use it in GitHub Desktop.
Save BinaryMoon/cca23cdb72a9ce42a0460e8d881ff021 to your computer and use it in GitHub Desktop.
Display Jetpack Related Posts in a local environment. Note that the thumbnails won't load - but it's good enough to be able to test styles
@websupporter
Copy link

Hi @BinaryMoon,
thanks a lot for this snippet. As long as there is no DEV-mode for related posts, this is a huge help. However, somehow jtt_related_posts_meta() didn't work for me and I altered it a bit. I thought, I drop it here :)

function jtt_relatedposts_filter_hits( $hits ) {
    
    global $wpdb;
    $sql = 'select ID from ' . $wpdb->posts . ' where post_status="publish" AND post_type="post" order by rand() limit 0, 3';
    $res = $wpdb->get_results( $sql );
    $hits = array();
    foreach( $res as $id ) {
        $hits[] = array( 'id' => $id->ID );
    }
    return $hits;
}
add_filter( 'jetpack_relatedposts_filter_hits', 'jtt_relatedposts_filter_hits', 100 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment