Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

wp_query not resetting, last post hanging

You don’t need to call wp_reset_query() here, because you’re not modifying the main query. Instead, call wp_reset_postdata().

You only need to call wp_reset_query() when modifying the main loop via query_posts() (which you shouldn’t do, anyway, so you should never need to call wp_reset_query()).

But new WP_Query(), with a properly instantiated loop – i.e. one that calls the_post() – will stomp on the $post data for the main query. So, after closing your custom WP_Query() loop, call wp_reset_postdata() to restore $post data to the main query.

Related Posts:

  1. Using wp_query is it possible to orderby taxonomy?
  2. “tax_query” parameter not working with WP_Query
  3. How do I exclude a custom taxonomy from the post loop
  4. Custom Taxonomy and Tax_Query
  5. WordPress database error: [Not unique table/alias: ‘wp_postmeta’]
  6. Using WordPress to make a “Product Search” type navigation drilldown
  7. Custom Taxonomy not working with posts_per_page in new WP_query (pagination problem)
  8. display posts with same taxonomy term
  9. Including all terms in wordpress tax_query
  10. How to get first post in a category of a custom taxonomy
  11. Display one post from each term in a custom taxonomy [closed]
  12. How much faster is a tax query than a meta query?
  13. Using tax_query creates a 1 = 0 or 1 = 1 in $wp_query->request
  14. Use custom posts as taxonomy term meta replacement?
  15. search query within custom taxonomy term, post title and meta field
  16. Is it possible to sort the post based on a custom field?
  17. wp query with multiple taxonomy?
  18. wp_query orderby title and meta key value (WP3.1)
  19. On Taxonomy Template page, want to add Post_Type
  20. Page queried instead of a custom taxonomy
  21. List Custom Taxonomy Values according to a Post Meta Value
  22. Custom WP_Query breaks default behaviour of viewing right post associated with tax-term!
  23. The next_posts_link() show me a aditional page in blank
  24. Help with a query not working with custom taxonomy
  25. Adding session variable and/or cookie based on user-selected input
  26. Excluding a custom taxonomy term breaks wp_get_post_terms
  27. Advanced Tax Query
  28. why do drafts return as part of wp_query?
  29. Improving WP_Query performance for multiple taxonomies
  30. WP Query with custom taxonomy
  31. how to search in custom fields & custom taxonomy for custom search
  32. get_the_terms() to show all custom taxonomies
  33. Single reusable value for post meta: Custom Taxonomy or Post Meta?
  34. WP_Query on custom taxonomy works fine but fails if run through wp_ajax_
  35. Advanced Query Logic With Multiple Taxonomies
  36. How do I Use Multiple Loops with WP_Query?
  37. cannot get multiple loops using tax_query
  38. Display all posts for taxonomy term across multiple custom post types
  39. Selecting all posts from the children of a particular parent taxonomy
  40. What is faster: custom taxonomy or serialized post-meta for db retrieval? (over 60,000 posts)
  41. Is it possible to store Json data in post_meta and manipulate
  42. Add Custom Taxonomy for Blog Meta Info
  43. How to separate posts in loop?
  44. Creating terms vs custom post meta to save data?
  45. Hiding taxonomies with no children WP_Query & tax_query
  46. Can I use OR relation for one item when calling tax_query from WP_Query and use AND for the rest?
  47. Set tax_query conditionally with new WP_Query
  48. querying posts by custom taxonomy terms right from a querystring based URL
  49. Does using custom taxonomy is more CPU efficient than using meta_data?
  50. Query custom taxonomy by term id?
  51. When filtering query on custom taxonomy; main menu dissapears
  52. Exclude taxonomy term from all loops, but having it on widget
  53. Why can’t I use an array of term slugs in WP_Query?
  54. Using WP_Query and Query_post for the loop?
  55. Problem with wordpress pagination
  56. How to do a particular wp_query taxonomy search
  57. Count of posts by different parameters?
  58. Wp_query…a type of term a different div
  59. check if a taxnomy queried in $wp_query?
  60. Taxonomy.php how to show post only in current taxonomy with wp_query?
  61. WP_Query tax_query – Show results if child has parent X
  62. WooCommerce custom taxonomy as meta?
  63. Query custom taxonomy for category including children
  64. Proper way to create taxonomy queries
  65. how to use tax_query to apply both terms or one if one is empty
  66. Get current page term title to use in WP_Query
  67. passing moree than one value of slugs in taxonomy using variable
  68. Sort taxonomy page alphabetically by meta rather than default post date
  69. Convert post meta to custom taxonomy?
  70. Count tags for current post and save into custom meta field (and update it on post edit)
  71. Is it possible to sort the post based on a custom field?
  72. Custom post type term names with ampersand in the term name
  73. WordPress custom post type
  74. Looking for suggestions on creating simple database (Help!!)
  75. Values inside a custom field to determine which category posts to display
  76. How do you move custom fields to custom taxonomies using WP Queries
  77. WordPress hiding posts without content on custom taxonomy query. How to solve?
  78. get meta fields and taxonomy of any post type
  79. Where to put a migration script to switch post information?
  80. Run next query based on first query’s term
  81. Get the original menu item name string instead of the label
  82. How to use tax_query other than by slug or id or solve custom taxonomy tags conflicts with pre-existing tags?
  83. Order posts with custom taxonomy array
  84. Getting grandchildren of a post with a specified custom taxonomy?
  85. Taxonomy Parameters in WP Query to get posts from two different taxonomies
  86. Update fields with post object and custom tax with wp_insert_post
  87. How can I show custom field according to taxonomy?
  88. Custom Taxonomy + JQuery Tabs
  89. Advanced AND tax_query in sidebar with 2 taxonomies
  90. How to query posts that are not related to any term of a taxonomy?
  91. Using wp_query is it possible to orderby taxonomy?
  92. How to limit posts to 1 from each term with tax_query?
  93. Loop posts without any taxonomy
  94. Custom taxonomy with custom meta value is not sorting correctly (query returns the same value for orderby regardless of sort column click)
  95. How to handle custom taxonomy archive when no posts will have that taxonomy
  96. How can I list all the meta in a custom taxonomy?
  97. Weekdays as terms – How to order taxonomy terms by ID in admin panel?
  98. Returning One custom taxonomy term name
  99. WP_Query – Accessing MetaValue from Query Result
  100. How to display ACF taxonomy checkbox links on WooCommerce product category archive
Categories custom-taxonomy Tags custom-taxonomy, post-meta, wp-query
Why can’t I use an array of term slugs in WP_Query?
Targeting categories in custom fields

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress