Currently using ACF Repeater for WP to show some posts within a category but if I add the same repeater I want it to keep a log of what post ids have been used so it can exclude them from the new loop.
The only problem is my current code works fine for the first loop and the second but adding anymore than two just resets back to the first set of posts. Dumping the array looks like it is not adding to the array just overwriting it.
First array looks like this
array(3) { [0]=> int(28890) [1]=> int(28790) [2]=> int(28785) }
Second array
array(3) { [0]=> int(28749) [1]=> int(1) [2]=> int(28484) }
Third
array(3) { [0]=> int(28890) [1]=> int(28790) [2]=> int(28785) }
Here is my code
<?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>
Arrays are still pretty new to me so your guidance will be greatly appreciated!
Here is the solution using information from this link. https://www.binarymoon.co.uk/2010/03/5-wordpress-queryposts-tips/
Add this to your functions file.
Then to use this you would do your loop as normal, and call âbm_ignorePost($post->ID);â for each post you want to ignore. The following example uses the same query twice, but will display totally different posts on each output.