WordPress pagination on custom script

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>';

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x