Properly using wp_reset_postdata(), wp_reset_query() and variable naming in queries

Categorized under:

Photo of author
Written By Brian Krogsgard

6 thoughts on “Properly using wp_reset_postdata(), wp_reset_query() and variable naming in queries”

  1. I’ve heard back and forth that for whatever reason, the use of the $wp_query original variable name is needed for pagination with custom post types. However, I can’t confirm. It’d be awesome if someone who knew definitively would chime in regarding that.

  2. Michael Beckwith
    I’ve heard back and forth that for whatever reason, the use of the $wp_query original variable name is needed for pagination with custom post types. However, I can’t confirm. It’d be awesome if someone who knew definitively would chime in regarding that.

    Yes. For pagination to work, it must be the main query. That means the best route to alternate a loop on CPT pages would be pre_get_posts().

  3. Can you write another WP_Query() snippet with pagination please? You suggest not to reassign the main $wp_query Is there another way to do it?

Comments are closed.

our sponsors

Hosting.com logo
Omnisend
Kinsta
Progress Planner
Elementor
WP Munich
Atarim
Patchstack

Looking for our logo?

You're in the right spot!

Check out our Logo & Style page.