Skip to content

Instantly share code, notes, and snippets.

@hjanuschka
Created April 7, 2018 18:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hjanuschka/aa0a68fbd6f3997cb4fc75580b0e6602 to your computer and use it in GitHub Desktop.
Save hjanuschka/aa0a68fbd6f3997cb4fc75580b0e6602 to your computer and use it in GitHub Desktop.
<?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