Post offset jumbling posts in WordPress

I have a post offset set in a WordPress theme I am developing, which is also using infinite scrolling.

Problem is, I’ve noticed that this seems to be jumbling up the posts and displaying some twice. I have numbered all posts from 1-14 to demonstrate this.

Read More

If I take out the following code, the posts display fine but the infinite scrolling is broken.

<?php
// get offset from $_POST object if its set else offset will be 1
$offset = isset( $_POST['offset'] ) ? intval( $_POST['offset'] ) : 3; 
$post_per_pages = isset( $_POST['offset'] ) ? 3 : 6 ;?>

<?php query_posts( 'posts_per_page=' . $post_per_pages . '&offset=' . $offset );?>

The idea was to have 12 posts loaded initially, then load 3 / a row at a time as the user scrolls down.

I have tried altering the numbers within the offset, including changing 3 -> 0 but could not find a solution to the problem.

Related posts