0

I am using WP for my RealEstate project where all properties are pulled from a custom table (wp_listing) and displayed in a custom page template (page-realestate.php).

I know WordPress has built-in pagination methods to deal with paged content (pages, posts lists). I want to use that same pagination methods for the list of properties I am fetching from my custom DB table.

Is this possible? How?

[EDIT]

Code is something like:

echo '<ul>';
$properties = $listing->getProperties();
for($i = 0; $i < count($properties) ; $i++) {
    echo '<li>' . $properties[$i]['address'] . '</li>';
}
echo '</ul>';
0

It is unclear exactly which "built-in pagination methods" you are looking for. WordPress uses several.

If you are looking for the next_posts_links and previous_posts_link functionality, write your own function as those built-in functions depend upon the $wp_query global as you can see in the source. I doubt it is worth the time and effort to try to hack that to work with data from your custom table.

If you want pagination as you see at the bottom of the admin edit post screen, the built-in function paginate_links is generic. So long as you pass in the proper values you can paginate your own data without a problem. I have done it, and it works well, but you have to be very careful with all the parameters. Based on the information in your question, I don't think I can write the code you need. Plus, I am not even sure if that is what you are looking for.

  • Thanks. I was looking for something like next_posts_links and previous_posts_link. But I think paginate_links is what offers more flexibility. I can get job done using this with mix of my own logic :) – aceph ali Mar 27 '13 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.