WordPress.org

Ready to get started?Download WordPress

Forums

get_pages offset without a number (8 posts)

  1. Code Junkie
    Member
    Posted 3 years ago #

    Hello,

    I'm trying to use get_pages() to load a set of pages, but I want the set of pages to start after the first 9 pages. As far as I can tell, to make the "offset" parameter work, the get pages function also needs to have a value for the "number" parameter. Is this true? If so, is there any way to get around this without using a separate get_pages function to get the number of pages first and then tell the number parameter how many pages there are? I'm trying to use as few functions as possible to find the set of pages I want.

    Thanks for any help!
    Code Junkie

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    As far as I can tell, to make the "offset" parameter work, the get pages function also needs to have a value for the "number" parameter. Is this true?

    i can't see this in the codex http://codex.wordpress.org/Function_Reference/get_pages

    have you tried it?

  3. Code Junkie
    Member
    Posted 3 years ago #

    It doesn't say anything about it in the codex, but in my client's site the "offest" paramater doesn't work on get_pages unless I specify a value for the "number" paramater. This client's site is running on WordPress 2.9.1 which may be the reason for this.

    My client has approved me to upgrade their WordPress installation to version 3.4.0 for other reasons, so soon I'll get to find out if this will fix it.

  4. yannbouschet
    Member
    Posted 3 years ago #

    I've got some problems with get_pages as well.

    For me, it looks like "offset" and "number" are not working if you try to use "child_of".
    Is it your case too ?

    I'm running WP 3.0.4 and the problem is still here.

  5. Code Junkie
    Member
    Posted 3 years ago #

    I upgraded WordPress yesterday and the "number"/"offset" problem is still happening for me. I also noticed that if I use child_of in version 2.9.1 with "number" and "offset", "number" doesn't work right unless I also add "parent" and specify the same value as "child_of". I haven't verified that this problem is happening in version 3.0.4, however.

  6. yannbouschet
    Member
    Posted 3 years ago #

    Thanks for the hint on using "parent". It fix some of my issues.
    That means the problem is still happening in 3.0.4.

    In the get_pages function the offset and number are used to set the LIMIT of an sql call like that :

    if ( !empty($number) )
    $query .= ' LIMIT ' . $offset . ',' . $number;

    So, if you don't set the "number", "offset" is useless.

    Hope that can help you.

  7. Code Junkie
    Member
    Posted 3 years ago #

    Ohhh that makes sense. Is there any value I can give number that will automatically call all of the posts after the offset?

    Also, you're welcome for the help!

  8. yannbouschet
    Member
    Posted 3 years ago #

    I guess if you just give a very large value to "number" that should do the trick, say 100000 or more ?

Topic Closed

This topic has been closed to new replies.

About this Topic