I’m showing on my front page only posts with featured image. My problem is that on every next page load I receive the same results aka getting duplicates. I’m using ordering by custom field. Any directions/ideas what may lead to this problem are welcome. Below is my main loop
// Layout
if(is_category())
{
$post_layout = blt_get_option('category_post_layout', 'normal');
}
elseif(is_author())
{
$post_layout = blt_get_option('author_post_layout', 'normal');
}
elseif(is_archive())
{
$post_layout = blt_get_option('archive_post_layout', 'normal');
}
else
{
$post_layout = blt_get_option('home_post_layout', 'normal');
}
$i = 1;
if(have_posts()){
while(have_posts()){
the_post();
get_template_part( 'inc/template-parts/content', $post_layout );
// Ad spot #4
if($ad_spot_between_posts = blt_get_option('spot_between_posts', 'none') != 'none'){
$ad_posts_frequency = blt_get_option('spot_between_posts_frequency', 3);
// take into account ad frequency
if(($i % (int) $ad_posts_frequency) == 0){
blt_get_ad_spot( 'spot_between_posts' );
}
}
$i++;
}
}else{
$has_posts = false;
}
And this is my index :
<?php get_header(); ?>
<div id="site-content" class="clearfix">
<?php
// Front Page - Top of container
if(is_front_page() and is_active_sidebar('front-top_of_container')){
dynamic_sidebar('front-top_of_container');
}
?>
<div id="site-content-column"><?php
if(is_archive()){
blt_get_title();
}
if(have_posts()){
echo '<div class="row">';
include(get_template_directory().'/loop.php');
echo '</div>';
// Previous/next page navigation.
if(!blt_get_option('enable_infinite_scrolling')){
the_posts_pagination(array(
'prev_text' => '<i class="fa fa-chevron-left"></i>',
'next_text' => '<i class="fa fa-chevron-right"></i>',
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'blue' ) . ' </span>',
));
}
}else{
get_template_part( 'inc/template-parts/content', 'none' );
} ?>
</div><?php
#
# SIDEBAR
# ========================================================================================
# Load the sidebar if needed
# ========================================================================================
#
if(in_array(blt_get_option('sidebar_layout', 'right'), array('left', 'right'), true)){
get_sidebar();
} ?>
</div>
<?php get_footer(); ?>
Edit: Infinite scroll function
function blt_infinitepaginate(){
$has_posts = true;
$type = isset($_POST['type']) ? $_POST['type'] : false;
$loopFile = $_POST['loop_file'];
$paged = $_POST['page_no'];
$posts_per_page = get_option('posts_per_page');
$post_id = isset($_POST['post_id']) ? $_POST['post_id'] : false;
# Load the posts
if($post_id){
include(get_template_directory().'/loop-hottest.php');
}else{
query_posts( array( 'paged' => $paged+1, 'post_status' => 'publish', 'post__not_in' => get_option('sticky_posts') ) );
include(get_template_directory().'/loop.php');
}
if(!$has_posts){
return false;
}
exit;
}
function blt_change_main_loop( $query ) {
if ( is_admin() || ! $query->is_main_query() )
return;
if ( is_home() and isset($_GET['page'])) {
$query->set( 'posts_per_page', $_GET['page'] * get_option('posts_per_page') );
return;
}
}
add_action( 'pre_get_posts', 'blt_change_main_loop', 1 );
}