@bulkmaker

Кольцевая перелинковка с кастомными типами записей?

У меня есть код который я использую для кольцевой перелинковки.
<?php
/**
 * Plugin Name: Линковка проектов
 */
function circular_links_post_ids($n){ // Линковка проектов 
	global $post;
	$nDisplay = $n;
	$cats = wp_get_post_categories($post->ID);
	if ($cats) {
		$args=array(
			'category__in' => $cats,
			'posts_per_page'=>-1,
			'caller_get_posts'=>1,
			'orderby'=>'date',
			'order'=>'ASC',
		);
 		$myposts = get_posts($args);
		foreach($myposts as $position=>$mypost){
			if($mypost->ID == $post->ID){
				$currPosition = $position-2;
				break;
			}
		}
		$total = count($myposts);
		$postsCount = $total - $currPosition;
		$postIDs = array();
		if($postsCount >= $nDisplay){
			for($i=0;$i<$nDisplay;$i++){
				$postIDs[] = $myposts[$currPosition+$i]->ID;
			}
		}else{
			for($j=0;$j<$postsCount;$j++){
				$postIDs[] = $myposts[$currPosition+$j]->ID;
			}
			$firstPostsNum = $nDisplay - $postsCount;
			for($z=0;$z<$firstPostsNum;$z++){
				$postIDs[] = $myposts[$z]->ID;
			}
		}
		$array2 = array ("ID" => "$post->ID");
		$postIDs = array_diff($postIDs, $array2);
		return $postIDs;
	}else{
		return false;
	}
}

function circular_links($numb){ // Линковка проектов 
		$orig_post = $post;
		$postIDs = circular_links_post_ids($numb);
		$args = array(
			'post__in' => $postIDs,
			'order' => 'ASC'
		);
		$my_query = new WP_Query($args);
		while( $my_query->have_posts() ) {
			$my_query->the_post();
			?>
			<?php 	get_template_part('parts/card-project2'); // шаблон карточки проекта ?>
		<?php }
		$post = $orig_post;
		wp_reset_query();
}


Как мне его переделать под кастомные типы записей и кастомные категории ?
  • Вопрос задан
  • 93 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы