HEX
Server: LiteSpeed
System: Linux server315.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: globfdxw (6114)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/globfdxw/public_html/wp-content/themes/alone/template-parts/post/related-posts.php
<?php
/**
 * The template for displaying Related Posts
 *
 * @package WordPress
 * @subpackage Alone
 * @since Alone 7.0
 */

if( 1 !== absint( alone_get_option( 'show_related_posts' ) ) ) {
  return;
}

global $post;

// Related category
$cats_array = array( 0 );
$cats = wp_get_post_terms( $post->ID, 'category' );
foreach ( $cats as $cat ) {
  $cats_array[] = $cat->term_id;
}
$cats_array = array_map( 'absint', $cats_array );

// Related tag
$tags_array = array( 0 );
$tags = wp_get_post_terms( $post->ID, 'category' );
foreach ( $tags as $tag ) {
  $tags_array[] = $tag->term_id;
}
$tags_array = array_map( 'absint', $tags_array );

$numbers = absint( alone_get_option( 'related_posts_number' ) );

$related = new WP_Query(
 array(
   'post_type'           => 'post',
   'posts_per_page'      => $numbers,
   'ignore_sticky_posts' => 1,
   'no_found_rows'       => 1,
   'order'               => 'rand',
   'post__not_in'        => array( $post->ID ),
   'tax_query'           => array(
     'relation' => 'OR',
     array(
       'taxonomy' => 'category',
       'field'    => 'term_id',
       'terms'    => $cats_array,
       'operator' => 'IN',
     ),
     array(
       'taxonomy' => 'post_tag',
       'field'    => 'term_id',
       'terms'    => $tags_array,
       'operator' => 'IN',
     ),
   ),
 )
);

if ( $related->post_count == 0 ) {
 return;
}

?>
<div class="related-posts-wrap">

  <?php if( alone_get_option( 'related_posts_heading' ) ) { ?>
    <h2 class="related-title"><?php echo alone_get_option( 'related_posts_heading' ); ?></h2>
  <?php } ?>

  <div class="related-posts-list">
    <?php
    while ( $related->have_posts() ) : $related->the_post();

      get_template_part( 'template-parts/content/content' );

    endwhile;
    wp_reset_postdata();

    ?>
  </div>

</div>