Pagination of wp_query posts

What’s the proper way to get pagination working on a foreach loop?

Here is what I have so far:

function remove_employees()
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;

/* Grabs the 500 records per page out of 3400 */
$wp_query = new WP_Query([
‘post_type’ => ’employee’,
‘post_status’ => ‘any’,
‘posts_per_page’ => 500,
‘paged’ => $paged,

/* Loops through and shows the 500 records */
foreach ($wp_query->posts as $query) {
$employee_name = get_post_meta($query->ID, ‘_employee_id’, true);
$octopus_id = get_post_meta($query->ID, ‘_octopus_id’, true);
echo $employee_name . ‘ has Octopus ID: ‘ . $octopus_id . ‘<br/>’;

next_posts_link( ‘NEXT &raquo;’, $wp_query->max_num_pages);

I get the 500 records printed out on the first loop and then it created the NEXT button at the bottom – When I click that button, it just redirects to the homepage of my site.

How would I make it loop until all 3400 records are shown?

Read more here:: Pagination of wp_query posts

Leave a Reply

Your email address will not be published. Required fields are marked *