Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'jnews_force_disable_inline_related_post', 'disable_inline_related_if_empty', 100 );
- function disable_inline_related_if_empty( $flag ) {
- if ( ! $flag ) {
- $match = get_theme_mod( 'jnews_single_post_inline_related_match', 'category' );
- $post_per_page = get_theme_mod( 'jnews_single_post_inline_related_number', 3 );
- $tag = $category = $result = array();
- $attr = array(
- 'number_post' => $post_per_page,
- 'include_tag' => implode( ',', $tag ),
- 'fields' => 'ids', // untuk performa
- 'post__not_in' => array( get_the_ID() ),
- );
- if ( $match === 'category' ) {
- \JNews\Single\SinglePost::getInstance()->recursive_category( get_the_category(), $result );
- if ( $result ) {
- foreach ( $result as $cat ) {
- $category[] = $cat->term_id;
- }
- }
- if ( ! empty( $category ) ) {
- $attr['cat'] = implode( ',', $category );
- }
- } elseif ( $match === 'tag' ) {
- $tags = get_the_tags();
- if ( $tags ) {
- foreach ( $tags as $cat ) {
- $tag[] = $cat->term_id;
- }
- }
- if ( ! empty( $tag ) ) {
- $attr['tag__in'] = implode( ',', $tag );
- }
- }
- $query = new WP_Query( $attr );
- if ( 0 === $query->found_posts ) {
- return true;
- }
- }
- return $flag;
- }
Advertisement
Add Comment
Please, Sign In to add comment