HEX
Server: Apache/2.4.29 (Ubuntu)
System: Linux bareserver 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64
User: root (0)
PHP: 7.2.24-0ubuntu0.18.04.17
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/html/site/newsite/wp-content/themes/ooze/template-parts/single/related-posts.php
<?php
global $post;
$post_id = $post->ID;

$related_posts_text = ooze_get_option('related_posts_text');
$no_of_related_posts = absint(ooze_get_option('no_of_related_posts'));
$order = esc_attr(ooze_get_option('related_posts_order'));
$orderby = esc_attr(ooze_get_option('related_posts_orderby'));

// Covert id to ID to make it work with query
if ('id' == $orderby) {
    $orderby = 'ID';
}

$category_ids = array();
$categories = get_the_category($post_id);

if (!empty($categories)):
    foreach ($categories as $cat):
        $category_ids[] = $cat->term_id;
    endforeach;
endif;

if (!empty($category_ids)):

    $related_posts_args = array(
        'category__in' => $category_ids,
        'post_type' => 'post',
        'post__not_in' => array($post_id),
        'posts_per_page' => $no_of_related_posts,
        'ignore_sticky_posts' => 1,
        'orderby' => $orderby,
        'order' => $order,
    );

    $related_posts_query = new WP_Query($related_posts_args);

    if ($related_posts_query->have_posts()):
        ?>
        <div class="single-related-posts-area theme-single-post-component">
            <header class="component-header single-component-header">
                <h2 class="single-component-title">
                    <?php echo esc_html($related_posts_text); ?>
                </h2>
            </header>
            <div class="component-content single-component-content">
                <?php while ($related_posts_query->have_posts()):
                    $related_posts_query->the_post(); ?>
                    <article id="post-<?php the_ID(); ?>" <?php post_class('theme-article theme-single-component-article'); ?>>
                        <?php if (has_post_thumbnail()): ?>
                            <div class="entry-image image-size-xsmall">
                                <a href="<?php the_permalink() ?>">
                                    <?php
                                    the_post_thumbnail('medium_large', array(
                                        'alt' => the_title_attribute(
                                            array(
                                                'echo' => false,
                                            )
                                        ),
                                    )
                                    );
                                    ?>
                                </a>
                            </div>
                        <?php endif; ?>
                        <div class="entry-details">
                            <h3 class="entry-title font-size-small line-clamp line-clamp-2 mb-8">
                                <a href="<?php the_permalink() ?>">
                                    <?php the_title(); ?>
                                </a>
                            </h3>
                            <div class="post-date">
                                <?php echo esc_html(get_the_date()); ?>
                            </div>
                        </div>
                    </article>
                <?php endwhile;
                wp_reset_postdata(); ?>
            </div>
        </div>

        <?php

    endif;

endif;