我希望将每个字词的帖子显示为字词,但无法停止重复的帖子
我的wordpress结构是:
父类别1
N.B。:有时帖子与2个类别相关联,如何删除重复项?
答案 0 :(得分:0)
你几乎就在那里,你只是没有在正确的位置填充$do_not_duplicate
,而你没有检查它是否已经在其中。
将您的if
块更改为类似的内容(未经测试,但它可以提供您的想法):
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
$post_id = get_the_ID();
if (in_array($post_id, $do_not_duplicate)) {
continue; // We've already seen this post ID, so skip the rest of the loop
}
$do_not_duplicate[] = $post_id;
?>
<tr>
<td><?php include (TEMPLATEPATH . '/contactfullname.php'); ?></td>
<td><?php echo get_post_meta($post->ID, 'ecpt_position', true); ?></td>
<td><?php echo p2p_get_meta( get_post()->p2p_id, 'table', true ); ?></td>
<td><?php echo ' ' .$term->name;?></td>
<td><?php echo p2p_get_meta( get_post()->p2p_id, 'confirmation', true ); ?></td>
</tr>
<?php
endwhile;
}
修改强>
抱歉,您看到$do_not_duplicate
中的$args
使用了while
。在这种情况下,移动代码以将其设置为if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate[] = get_the_ID(); ?>
循环可能就足够了:
size_t length = strlen(line);
if(length > MAX_LENGTH)
{
length = MAX_LENGTH;
}
memcpy(aux, line, length);
aux[length] = '\0';