wordpress posts_per_page returning wrong output

I am facing one strange issue and hope to get right direction from some experienced. in our test case the below query is listing 100 post per page and when we go to next page again 100 without any issue but i have seen several clients, they have one 2-10 listing on first page and seems offset does not work or something i am missing. i think when i am giving offset i should not give ID & compare in arguments probably.

it list images in a table and i am aware that a post may contain or not contain images. we have tested with 1000 of post in random order and in between images and it worked jut fine but in several client cases it was not working when we checked through teamviewer.

we have noticed that we were not adding wp_reset_postdata(); at end and few suggested that it will solve the problem but i have doubt that it can solve the issue as without it also it was working perfectly in our test cases. any direction will be great

while ( $has_more_images ) {

$args = array(
‘posts_per_page’ => ‘100’,
‘offset’ => $offset,
‘post_type’ => ‘attachment’,
‘post_status’ => ‘any’,
‘orderby’ =>’ID’,
‘order’ => ‘ASC’,
‘ID’ => $comp_last_id,
‘compare’ => ‘>’,
‘no_found_rows’ => true


$the_query = new WP_Query( $args );
if ( $the_query -> have_posts () ) {
while ( $the_query -> have_posts () ) {
$the_query -> the_post ();
$idall = get_the_ID ();


Read more here:: wordpress posts_per_page returning wrong output

Leave a Reply

Your email address will not be published. Required fields are marked *