WP_Query issue with supress_filters flag
-
Hello,
I have a big issue since I installed acf-better-search plugin.
My wordpress is a multi lang.
I have some batch scripts fetching all posts (FR and EN) but since I install acf-better-search plugin, the WP-Query (or get_posts()) is returning only post on the default language even if I add [ suppress_filter => true ] option.After long hours analysing, I found that your plugin was always forcing suppress_filter = false for ALL WP queries ! See the following code (Query.php)
<?php namespace AcfBetterSearch\Search; use AcfBetterSearch\HookableInterface; /** * . */ class Query implements HookableInterface { /** * {@inheritdoc} */ public function init_hooks() { add_filter( 'pre_get_posts', [ $this, 'query_args' ] ); } public function query_args( \WP_Query $query ): \WP_Query { if ( ! isset( $query->query_vars['s'] ) ) { return $query; } $query->query_vars['suppress_filters'] = false; return $query; } }
As you can see, when $query->query_vars[‘s’] is not set, you are forcing ‘suppress_filters’ to false.
In fact, with a recent wordpress (5.8 by example), WordPress starts filling the query_vars so the ‘s’ parameter is always set !!!
(see fill_query_vars() in class-wp_query.php of wordpress core).I think you should add a condition, checking $query->query_vars[‘s’] is not an empty string.
- The topic ‘WP_Query issue with supress_filters flag’ is closed to new replies.