Created
April 7, 2018 18:57
-
-
Save hjanuschka/aa0a68fbd6f3997cb4fc75580b0e6602 to your computer and use it in GitHub Desktop.
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
<?php | |
/* | |
ACF - even when used with json/php files only, has the problem that it triggers a wpquery | |
that does not scale if you reach a certain amount of wp_post's. | |
to bypass this, we hook into posts_pre_query and disable the ACF lookup that is slow. | |
this DISABLES to ability to use DB stored acf settings, you'd need to load the json/php files. | |
to provide a little bit better DEV-XP - you can bypass this bypass :D - with WP_DEBUG=true | |
*/ | |
add_filter('posts_pre_query', array( $this, 'acf_posts_pre_query' ), 15, 2); | |
public function debug_enabled() { | |
if(defined("WP_DEBUG") && WP_DEBUG == true) { | |
return true; | |
} | |
return false; | |
} | |
public function acf_posts_pre_query($posts, \WP_Query $query) | |
{ | |
if (is_object($query) && property_exists($query, 'query_vars') && $query->query_vars['post_type'] == 'acf-field-group' && !$this->debug_enabled()) { | |
return array(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment