Bypass “supress_filters” in WP Query

Apparently, for some illogical reason, the developers decided that the only way to fetch posts in all languages, is to add supress_filters=true to the WP_Query (instead of having like say, a language_code=all option).

Anyways, I am in a situation where I need to fetch posts in all languages, but ALSO modify the WP_Query using filters. Is there a way to enforce that my filters are being added to the query, even though supress_filters is set to false?

This is the filter I need to add:

add_filter( ‘posts_where’, function($where, $wp_query) {
global $wpdb;

if($search_term = $wp_query->get( ‘custom_search’ )){
$search_term = $wpdb->esc_like($search_term);
$search_term = ‘ ‘%’ . $search_term . ‘%”;
$where .= ‘ AND (‘ . $wpdb->posts . ‘.post_title LIKE ‘ . $search_term . ‘ OR ‘ . $wpdb->posts . ‘.ID LIKE ‘ . $search_term . ‘ OR ‘ . $wpdb->posts . ‘.post_name LIKE ‘ . $search_term . ‘)’;
}

return $where;
}, 10, 2 );

But it is removed after adding supress_filters=true (because I need to fetch posts in ALL languages)

Read more here:: Bypass “supress_filters” in WP Query

Leave a Reply

Your email address will not be published. Required fields are marked *