Numeric pagination custom post type

You’re referencing the global $wp_query object in your function which you’ve reset using wp_reset_query(). You can resolve the pagination by passing your custom $loop WP_Query object to the function. I also changed wp_reset_query to wp_reset_postdata Also you’re making the call to your pagination function in the while loop instead of after it. Your function should … Read more

When should you use wp_reset_postdata vs wp_reset_query?

wp_reset_postdata() resets the value of the global $post variable to the post property of the main query, which will be whatever post the main query was last on. You would do this if you had used setup_postdata() or $query->the_post() on a custom query. Both of these replace the global $post variable so that functions like … Read more

wp_reset_postdata() or wp_reset_query() after a custom loop?

The difference between the two is that wp_reset_query() – ensure that the main query has been reset to the original main query wp_reset_postdata() – ensures that the global $post has been restored to the current post in the main query. Indeed, looking at the source you’ll see that the wp_reset_query() calls wp_reset_postdata(). The only difference … Read more