• Resolved nicoleadoff

    (@nicoleadoff)


    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter nicoleadoff

    (@nicoleadoff)

    UPDATE:
    When I say:

    As you can see, when $query->query_vars[‘s’] is not set, you are forcing ‘suppress_filters’ to false.

    You must read:

    As you can see, when $query->query_vars[‘s’] is set, you are forcing ‘suppress_filters’ to false.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hello @nicoleadoff,

    Thanks for your message.

    Thank you very much for your report. I have released an update (version 4.0.1) which fixes the problem you mentioned. I really appreciate your commitment to the development of the plugin.

    Best,
    Mateusz

    Thread Starter nicoleadoff

    (@nicoleadoff)

    Thanks for the fix!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WP_Query issue with supress_filters flag’ is closed to new replies.