= 4 && ! is_numeric( $word ) && ! in_array( $word, $stopwords, true ) ) {
$words[] = $word;
}
}
$words = array_unique( $words );
if ( empty( $words ) ) {
return array();
}
$score_title = function ( $candidate_id ) use ( $words ) {
$candidate = strtolower( (string) get_the_title( $candidate_id ) );
$score = 0;
foreach ( $words as $word ) {
if ( false !== strpos( $candidate, $word ) ) {
$score++;
}
}
return $score;
};
$ranked = array();
$add_pool = function ( $pool, $same_cat ) use ( &$ranked, $score_title ) {
foreach ( $pool as $candidate_id ) {
$score = $score_title( $candidate_id );
if ( $score > 0 ) {
$ranked[] = array(
'id' => (int) $candidate_id,
'score' => $score,
'same_cat' => $same_cat,
'time' => (int) get_post_time( 'U', true, $candidate_id ),
);
}
}
};
$same_cat = get_posts( array(
'post_type' => 'post',
'post_status' => 'publish',
'category__in' => $cats,
'post__not_in' => array( $post_id ),
'posts_per_page' => 60,
'orderby' => 'date',
'order' => 'DESC',
'fields' => 'ids',
) );
$add_pool( $same_cat, 1 );
$others = get_posts( array(
'post_type' => 'post',
'post_status' => 'publish',
'category__not_in' => $cats,
'post__not_in' => array( $post_id ),
'posts_per_page' => 200,
'orderby' => 'date',
'order' => 'DESC',
'fields' => 'ids',
) );
$add_pool( $others, 0 );
usort( $ranked, function ( $a, $b ) {
if ( $a['same_cat'] !== $b['same_cat'] ) {
return $b['same_cat'] - $a['same_cat'];
}
if ( $a['score'] !== $b['score'] ) {
return $b['score'] - $a['score'];
}
return $b['time'] - $a['time'];
} );
$ids = array();
foreach ( $ranked as $item ) {
$ids[] = $item['id'];
if ( count( $ids ) >= 6 ) {
break;
}
}
return array_values( array_unique( $ids ) );
}
}
if ( ! function_exists( 'nn_shortcode_related_v3' ) ) {
function nn_shortcode_related_v3() {
$ids = nn_related_post_ids_v3();
if ( empty( $ids ) ) {
return '';
}
$out = '
';
return $out;
}
}
add_shortcode( 'nn_related', 'nn_shortcode_related_v3' );
?>
Langsung ke isi
NIAS – Kelangkaan air bersih yang melanda sejumlah kawasan di Indonesia turut dirasakan oleh warga di pedalaman, tak terkecuali Pondok Pesantren Tahfidz Gunung Sitoli