I'm bit confused about paginating the results generated from an array in WordPress. I've a couple of event Ids per user that I'm saving as a string: -
id | userid | eventids
1 | 22 | 33,45,554, 225
I fetch these results using $wpdb->get_var ($query), for which I get a string "33,45,554,225". I'm then converting this string into an array so that I can process it further.
So, $eventsList = explode ( ",", $wpdb->get_var($query) );
I then fetch the event titles using following loop:
foreach ( $eventsList as $event ) {
echo get_the_title ($event);
}
Now the problem is that I do not know how to paginate these results. I've the following standard code that generates the pagination links, but each page shows the same data.
$big = 999999999; // need an unlikely integer
$countOfEvents = count( $eventsList );
$page_count = ceil($countOfEvents / $eventsPerPage );
$employer_dashboard_pagination_args = array(
'base' => str_replace( $big, '%#%', esc_url (get_pagenum_link( $big )) ),
'format' => '/page/%#%',
'current' => $paged,
'total' => $page_count,
'prev_text' => '« Previous',
'next_text' => 'Next »'
);
Would really appreciate if someone could help fixing this problem.