I want to display all posts starting from a certain offset, my query is:
WP_Query( array( 'posts_per_page' => -1, 'offset' => 20, 'cat' => 5, ) );
This query shows all posts without starting from the offset value. Whys is that?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.Sign up to join this community
offset index for WP_Query generally works with pagination. When you set pagination to a
-1 the function assumes you're getting all posts and there will be no pagination or offset. So to counteract this you would set the
posts_per_page to a high number like 999. Reading the [Function Reference on WP_Query][enter link description here]1 the pagination section says:
'posts_per_page'=>-1to show all posts (the
'offset'parameter is ignored with a -1 value). Set the ‘paged’ parameter if pagination is off after using this parameter.