WordPress.org

Ready to get started?Download WordPress

Forums

Record paging with $wpdb (4 posts)

  1. Dystopia777
    Member
    Posted 6 years ago #

    Hi,

    I've been trying to get my head around the $wpdb object and having looked briefly at the manual I couldn't see there being any automagical way of paging records.

    Am I right to think that the wpdb object is just for query abstraction and implementing paging routines is something you have to do for yourself?

    Any help appreciated.

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Paging routines? Could you be a bit more specific about what you're talking about?

    If you mean the pages as in page 2 shows the next 10 posts, then that's implemented, but in the WP_Query object, not in the WP_DB object. The query controls the actual querying of posts and such.

  3. Dystopia777
    Member
    Posted 6 years ago #

    Sure, sorry. I'm having a go at writing a simple plugin that lists rows from a table I have created myself. I wanted to know if there was a built in way of paging result sets, just like you suggested - 10 per page or whatever.

    I'll have a look at the docs for wp_query.

    Any advice appreciated!

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    If this is for a table you made yourself, then wp_query won't help you.

    The way WordPress does paging is by using the MySQL LIMIT parameter. So to get the first page of 10, it does LIMIT 0,10. To get the second page, it does LIMIT 10,10.

    Basically, it's LIMIT offset,row-count.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags