1
當前使用ACF Repeater for WP來顯示某個類別中的某些帖子,但是如果我添加了同一個中繼器,我希望它保留一個日誌,記錄已經使用後的id,因此它可以排除他們從新的循環。忽略已在循環中使用的wordpress中的帖子
唯一的問題是我當前的代碼對於第一個循環和第二個循環都正常工作,但是添加的不止兩個只是重置回第一組職位。轉儲數組看起來好像不會將數組添加到數組中。
第一陣列看起來像這樣
array(3) { [0]=> int(28890) [1]=> int(28790) [2]=> int(28785) }
二陣列
array(3) { [0]=> int(28749) [1]=> int(1) [2]=> int(28484) }
三
array(3) { [0]=> int(28890) [1]=> int(28790) [2]=> int(28785) }
這裏是我的代碼
<?php
$cat = get_sub_field('category_name');
$args = array(
'posts_per_page' => 3,
'category_name' => $cat,
'post__not_in' => $ids
);
query_posts($args);
$ids = array();
?>
<div class="hub-cont">
<?php while (have_posts()) : the_post(); ?>
<?php array_push($ids,get_the_ID()); /*$ids[] = get_the_ID();*/?>
<div class="blockitem2 small-12 medium-4 large-4">
<?php
// Fetch all posts relating to a certain tag then display 4 of them
//Get the Thumbnail URL
$src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(720,405), false, '');
?>
<div id="promolink"></div><div class="blockimage" style="background-image: url('<?php echo $src[0]; ?>'); background-repeat: no-repeat; background-size: cover;">
<div class="cats"><?php echo the_category(' '); ?></div>
</div>
<div class="meta">
<a class="gdbnewslink dark" href="<?php echo get_permalink();?>" ><?php the_title();?> </a>
</div>
<div class="clear"></div>
<div id="newsintro"><?php $text = $post->post_content; $trimmed = wp_trim_words($text, 50, null); echo $trimmed; ?></div>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php var_dump($ids); ?>
</div>
陣列對我來說仍然很新,所以您的指導將非常感謝!
新迴路從哪裏開始?新循環是否調用完全相同的代碼,那麼它將不起作用,因爲您將'$ ids'重置爲空數組。 – Luceos
是的,循環再次是相同的代碼。我認爲這是重置數組,我怎麼能夠創建可重複的代碼,而不重置數組? – Kyon147