DocumentationOnline documentation for Ajax Load More
Exclude Posts
The code below will exclude posts that have been included in a previous query on the page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php // Standard WP Query $args = array( 'category_name' => 'wordpress', 'posts_per_page' => 5 ); $query = new WP_Query($args); while ( $query->have_posts() ) : $query->the_post(); $do_not_duplicate[] = $post->ID; // Store post ID in array // Other loop actions could go here endwhile; wp_reset_query(); // Ajax Load More $post__not_in = ($do_not_duplicate) ? implode(',', $do_not_duplicate) : ''; echo do_shortcode('[ajax_load_more post__not_in="'. $post__not_in .'"]'); |
The code below will exclude the current post from Ajax Load More results.
1 2 3 4 |
<?php $current_id = get_the_ID(); // Current post ID echo do_shortcode('[ajax_load_more post__not_in="'. $current_id .'"]'); ?> |