Fixes an unclosed WP_Query() or query_posts() before Advanced Ads loads an ad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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