나는 custum 분류법을 기반으로 관련 게시물을 표시하려고합니다. 나는 wordpress.org에서 그런 종류의 작품을 찾았습니다. 그러나 원본 게시물은 여러 번 결과에 중복됩니다. (단어는 내가 사용하는 맞춤 분류법의 이름입니다) 무슨 일이 일어날 것인가는 단일 게시물이 표시되는 양에 따라 복제된다는 것입니다. 어떤 생각이 그 원인일까요?사용자 정의 분류 문제로 Wordpress 관련 게시물
코드 :
<?php
//for in the loop, display all "content", regardless of post_type,
//that have the same custom taxonomy (e.g. words) terms as the current post
$backup = $post; // backup the current object
$found_none = '<h2>No related posts found!</h2>';
$taxonomy = 'words';// e.g. post_tag, category, custom taxonomy
$param_type = 'words'; // e.g. tag__in, category__in, but genre__in will NOT work
$post_types = get_post_types(array('public' => true), 'names');
$tax_args=array('orderby' => 'none');
$tags = wp_get_post_terms($post->ID , $taxonomy, $tax_args);
if ($tags) {
foreach ($tags as $tag) {
$args=array(
"$param_type" => $tag->slug,
'post__not_in' => array($post->ID),
'post_type' => $post_types,
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = null;
$my_query = new WP_Query($args);
if($my_query->have_posts()) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
<?php $found_none = '';
endwhile;
}
}
}
if ($found_none) {
echo $found_none;
}
$post = $backup; // copy it back
wp_reset_query(); // to use the original query again
?>
안녕하세요, DeadMedic, 답장을 보내 주셔서 감사합니다. 나는 조정을했지만, 불행히도 나는 여전히 중독자가된다. 실제로 코드 $ post_not_in = array ($ post-> ID)를 완전히 무시한 것 같습니다. 내가 그것을 넣든 안 넣든 상관 없습니다. 결과는 같습니다. 아마도 뭔가 간단한 오류 일 수도 있지만 그게 뭔지 알 수는 없습니다 .. – Nordin
어떤 WordPress 버전을 사용하고 있습니까? – TheDeadMedic
2.9.2와 협력 중입니다. – Nordin