Title: offset problem with query_posts
Last modified: August 18, 2016

---

# offset problem with query_posts

 *  [yoru](https://wordpress.org/support/users/yoru/)
 * (@yoru)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/offset-problem-with-query_posts/)
 * i was searching for a way to implement ‘offset’ with query_posts() then i came
   across this code in wordpress trac
 * [http://trac.wordpress.org/ticket/2558](http://trac.wordpress.org/ticket/2558)
 * i modified the codes in the classes.php in wordpress 2.0.3 to do the trick here(
   [http://cureless.net](http://cureless.net)) where i am able to EXCLUDE some categories
   from the main index template and at the same time show the preceeding xx number
   of entries using query_posts(‘cat=-XX&showposts=XX&offset=X’) in 2 loops.
 * my question is: is offset in query_posts() already supported in wp 2.0.4? i’m
   planning to upgrade but i’m afraid i’ll mess up with the codes i modified.
 * i would appreciate it if someone points me to the list of upgrades/modifications
   from wp 2.0.3 to wp 2.0.4.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Joshua Sigar](https://wordpress.org/support/users/alphaoide/)
 * (@alphaoide)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/offset-problem-with-query_posts/#post-431661)
 * Well, I haven’t checked the source code of 2.0.4 (I’ll leave that as a homework
   for you) but trac marked that fix for 2.1 release.
 *  Thread Starter [yoru](https://wordpress.org/support/users/yoru/)
 * (@yoru)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/offset-problem-with-query_posts/#post-431669)
 * thanks! i just checked 2.0.4 and found codes similar to that in the trac
 * (part of) classes.php in 2.0.3
    ` if (($q['what_to_show'] == 'posts')) { $pgstrt
   = ''; $pgstrt = (intval($page) -1) * $q['posts_per_page'] . ', '; $limits = '
   LIMIT '.$pgstrt.$q['posts_per_page']; }
 * modified classes.php (based on trac)
    ` if (($q['what_to_show'] == 'posts')) {
   if ( empty($q['offset']) ) { $pgstrt = ''; $pgstrt = (intval($page) -1) * $q['
   posts_per_page'] . ', '; $limits = 'LIMIT '.$pgstrt.$q['posts_per_page']; } else{//
   we're ignoring $page and using 'offset' $pgstrt = intval($q['offset']) . ', ';
   $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page']; } }
 * 2.0.4
    ` if (($q['what_to_show'] == 'posts')) { $q['offset'] = abs(intval($q['
   offset'])); if ( empty($q['offset']) ) { $pgstrt = ''; $pgstrt = (intval($page)-
   1) * $q['posts_per_page'] . ', '; $limits = 'LIMIT '.$pgstrt.$q['posts_per_page'];}
   else { // we're ignoring $page and using 'offset' $pgstrt = $q['offset'] . ',';
   $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page']; } }
 * also added ‘offset’ as a query var in WP 2.0.3 from the trac:
    ` var $private_query_vars
   = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show','
   showposts', 'nopaging', 'show_post_type');
 * i don’t see same code in the WP 2.0.4 version of classes.php

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘offset problem with query_posts’ is closed to new replies.

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [classes](https://wordpress.org/support/topic-tag/classes/)
 * [exclude](https://wordpress.org/support/topic-tag/exclude/)
 * [loops](https://wordpress.org/support/topic-tag/loops/)
 * [offset](https://wordpress.org/support/topic-tag/offset/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)
 * [upgrade](https://wordpress.org/support/topic-tag/upgrade/)

 * 2 replies
 * 2 participants
 * Last reply from: [yoru](https://wordpress.org/support/users/yoru/)
 * Last activity: [19 years, 9 months ago](https://wordpress.org/support/topic/offset-problem-with-query_posts/#post-431669)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
