WPML: WP_Query + suppress_filters not working

admin2025-01-07  7

I'm working on a fix to a WordPress multi-language site using WPML. This website has two different domains, one for english and one for french. French is the main language.

For all the website when I retrieve posts the language of the website is respected in the query, but there is a query in the theme's footer.php, to retrieve some alerts, which is returning posts in any language. this is the query:

<?php
$args = array(
    'post_type' => 'post',
    'cat' => 8,
    'posts_per_page' => 1,
    'meta_key' => 'traffic-level',
    'meta_value' => 1,
    'suppress_filters' => false
);

$query = new WP_Query( $args );
wp_reset_query();

if( $query->have_posts() ):

    while( $query->have_posts() ) : $query->the_post();?>

     print the post...

    <?php endwhile;

endif;?>

In all the other pages suppress_filters' => false is not set. I added this because I saw it in the plugin's forum but it's not working properly yet. I also checked my functions.php to see if there was a pre_get_posts action that could be messing with the query and there isn't.

Am I missing something in this query? What else could I do to fix it?

Thanks for any help

I'm working on a fix to a WordPress multi-language site using WPML. This website has two different domains, one for english and one for french. French is the main language.

For all the website when I retrieve posts the language of the website is respected in the query, but there is a query in the theme's footer.php, to retrieve some alerts, which is returning posts in any language. this is the query:

<?php
$args = array(
    'post_type' => 'post',
    'cat' => 8,
    'posts_per_page' => 1,
    'meta_key' => 'traffic-level',
    'meta_value' => 1,
    'suppress_filters' => false
);

$query = new WP_Query( $args );
wp_reset_query();

if( $query->have_posts() ):

    while( $query->have_posts() ) : $query->the_post();?>

     print the post...

    <?php endwhile;

endif;?>

In all the other pages suppress_filters' => false is not set. I added this because I saw it in the plugin's forum but it's not working properly yet. I also checked my functions.php to see if there was a pre_get_posts action that could be messing with the query and there isn't.

Am I missing something in this query? What else could I do to fix it?

Thanks for any help

Share Improve this question asked Mar 11, 2020 at 16:43 André LuizAndré Luiz 1191 silver badge3 bronze badges 2
  • 1 Are you sure you set the language information correctly for those posts? (Eg they need to have an associated translation) – Tofandel Commented Mar 11, 2020 at 17:19
  • @Tofandel hi, yes. When I go to the post inside the admin, I can see the link between them. When I go to the french I see there is an english translation and when I go to the post in english it says it's a translation of the french post. – André Luiz Commented Mar 12, 2020 at 12:36
Add a comment  | 

1 Answer 1

Reset to default 0

I was facing the same issue, it seems suppress_filters needs to be set to true so you actually suppress those filters!

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736265175a1025.html

最新回复(0)