HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.33
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,pcntl_unshare,
Upload Files
File: /var/www/html/wpmuhibbah_err/wp-content/themes/goodwish/includes/edgtf-related-posts.php
<?php

if ( ! function_exists('goodwish_edge_get_related_post_type')) {
	/**
	 * Function for returning latest posts types
	 *
	 * @param $post_id
	 * @param array $options
	 * @return WP_Query
	 */
	function goodwish_edge_get_related_post_type($post_id, $options = array()) {

		$post_type = get_post_type($post_id);
		//Get tags & categories
		$tags = array();
		$categories = array();
		switch ($post_type) {
			case 'portfolio-item':
				$tags = wp_get_object_terms($post_id, 'portfolio-tag');
				$categories = wp_get_object_terms($post_id, 'portfolio-category');
				break;			
			case 'edge-event':
				$categories = wp_get_object_terms($post_id, 'edge-event-category');
				break;
			default:
				$tags = get_the_tags($post_id);
				$categories = get_the_category($post_id);
			break;
		}

		$tag_ids = array();
		if ($tags) {
			foreach ($tags as $tag) {
				$tag_ids[] = $tag->term_id;
			}
		}

		$category_ids = array();
		if ($categories) {
			foreach ($categories as $category) {
				$category_ids[] = $category->term_id;
			}
		}

		// var_dump($category_ids);

		$hasRelatedByTag = false;
		$hasRelatedByCategory = false;

		if ($tag_ids) {

			if ($post_type == 'portfolio-item') {
				$related_by_tag = goodwish_edge_get_related_custom_post_type_by_param($post_id, $tag_ids, 'portfolio-tag', $options); //For Custom Posts
			} else {
				$related_by_tag = goodwish_edge_get_related_posts($post_id, $tag_ids, 'tag', $options);
			}

			if (!empty($related_by_tag->posts)) {
				$hasRelatedByTag = true;
				return $related_by_tag;
			}
			$hasRelatedByTag = false;

		}
		if ($categories && !$hasRelatedByTag) {

			if ($post_type == 'portfolio-item') {
				$related_by_category = goodwish_edge_get_related_custom_post_type_by_param($post_id, $category_ids, 'portfolio-category', $options);
			} elseif ($post_type == 'edge-event') {
				$related_by_category = goodwish_edge_get_related_custom_post_type_by_param($post_id, $category_ids, 'edge-event-category', $options);
			} else {
				$related_by_category = goodwish_edge_get_related_posts($post_id, $category_ids, 'category', $options);
			}

			if (!empty($related_by_category->posts)) {
				$hasRelatedByCategory = true;
				return $related_by_category;
			}
			$hasRelatedByCategory = false;

		}

	}

}

if ( ! function_exists('goodwish_edge_get_related_posts') ) {
	/**
	 * Function for related posts
	 *
	 * @param $post_id - Post ID
	 * @param $term_ids - Category or Tag IDs
	 * @param $slug - term slug for WP_Query
	 * @param array $options
	 * @return WP_Query
	 */
	function goodwish_edge_get_related_posts($post_id, $term_ids, $slug, $options = array()) {

		//Query options
		$posts_per_page = -1;

		//Override query options
		extract($options);

		$args = array(
			'post__not_in'  => array($post_id),
			$slug . '__in'  => $term_ids,
			'order'         => 'DESC',
			'orderby'       => 'date',
            'post_status'   => 'publish',
			'posts_per_page'	=> $posts_per_page
		);

		$related_posts = new WP_Query($args);

		return $related_posts;

	}
}

if ( ! function_exists('goodwish_edge_get_related_custom_post_type_by_param') ) {
	/**
	 * @param $post_id - Post ID
	 * @param $term_ids - Category or Tag IDs
	 * @param $taxonomy
	 * @param array $options
	 * @return WP_Query
	 */
	function goodwish_edge_get_related_custom_post_type_by_param($post_id, $term_ids, $taxonomy, $options = array()) {

		//Query options
		$posts_per_page = -1;

		//Override query options
		extract($options);

		$args = array(
			'post__not_in'  => array($post_id),
			'order'         => 'DESC',
			'orderby'       => 'date',
			'posts_per_page'	=> $posts_per_page,
			'tax_query'     => array(
				array(
					'taxonomy'  => $taxonomy,
					'field'     => 'term_id',
					'terms'     => $term_ids,
				),
			)
		);

		$related_by_taxonomy = new WP_Query($args);

		return $related_by_taxonomy;

	}

}