Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@webzunft
Created September 25, 2020 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webzunft/1861a14c75eca0fb1a903c2d547c5f28 to your computer and use it in GitHub Desktop.
Save webzunft/1861a14c75eca0fb1a903c2d547c5f28 to your computer and use it in GitHub Desktop.
Fixes an unclosed WP_Query() or query_posts() before Advanced Ads loads an ad
/**
* Fix the "Current post is not identical to main post."
* and "Current query is not identical to main query." warnings in Advanced Ads
* caused by custom queries not using wp_reset_postdata() or wp_reset_query()
*
* @source https://wpadvancedads.com/manual/ad-debug-mode/
* @source https://developer.wordpress.org/reference/classes/wp_query/
* @source https://developer.wordpress.org/reference/functions/query_posts/
*
* Developers should not use this and rather add wp_reset_postdata() or wp_reset_query() to their code
* We are using wp_reset_postdata() because it is less invasive and doesn’t reset the whole query
*/
add_filter( 'advanced-ads-ad-select-args', function( $args ) {
// reset post data
wp_reset_postdata();
return $args;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment