Skip to content

Instantly share code, notes, and snippets.

@drrobotnik
Created November 4, 2015 19:15
Show Gist options
  • Save drrobotnik/1a1ffd7e316cd67754bc to your computer and use it in GitHub Desktop.
Save drrobotnik/1a1ffd7e316cd67754bc to your computer and use it in GitHub Desktop.
exclude posts within the hidden-posts options array
<?php
/*
Code references:
Exclude Posts:
https://jetpack.me/support/customize-related-posts/#exclude
Hidden posts plugin to grab post list to exclude:
https://vip-svn.wordpress.com/plugins/hidden-posts/hidden-posts.php
*/
function tt_exclude_related_post( $exclude_post_ids, $post_id ) {
// $post_id is the post we are currently getting related posts for
$hidden_posts = array_filter( array_map( 'absint', get_option( 'hidden-posts', array() ) ) );
if( !empty( $hidden_posts ) ) {
$exclude_post_ids = array_unique( array_merge( $exclude_post_ids, $hidden_posts ) );
}
return $exclude_post_ids;
}
add_filter( 'jetpack_relatedposts_filter_exclude_post_ids', 'tt_exclude_related_post', 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment