This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This thread is resolved. Here is a description of the problem and solution.

Problem: Suppress filters is not working correctly on the query. It's retrieving all posts regardless of language.

Solution: Make sure you are using the WP_Query method of fetching posts instead of the get_posts. With WP_Query you can use the suppress_filters parameter but with get_posts you will have to use the "pre_get_posts" action to insert the suppress_filters parameter in the query.

This topic contains 7 replies, has 4 voices.

Last updated by Michael 3 years, 5 months ago.

Assigned support staff: Yuri.

Author Posts
April 28, 2016 at 7:02 pm #871541

yuriyY-2

I'm having problems to show all posts in all languages of a custom post type in a query. 'suppress_filters' => true not working.

$wp_query = new WP_Query();
     query_posts(
        array(
         'suppress_filters' => true,
         'post_type' => 'blog_post',
         'showposts' => -1,
         'tax_query' => array(
                 array(
                     'taxonomy' => 'blog_category',
                     'field'    => 'slug',
                     'terms'    => 'update-notes',
                     'operator' => 'NOT IN'
                 )
             )
         )
     );
     if(have_posts()):
     while ($wp_query -> have_posts()) : $wp_query -> the_post($post->ID);

     the_title();

     endwhile; endif;
     wp_reset_query();
April 29, 2016 at 1:29 pm #872120

Yuri

Hi Yuri, I've noticed that in your code you are instancing the WP_Query object and assigning it to the $wp_query variable but you are not using it to create you query. You are triggering the query_posts function without assigning it to any variable.

Can you rework your code to use only the WP_Query instance with the parameters you configured for the query_posts call? This should resolve the issue.

Regards,
Yuri.

April 29, 2016 at 2:33 pm #872195

yuriyY-2

Hi, I already did that, same result.

    $args = array(
        'suppress_filters' => true,
        'post_type' => 'blog_post',
        'showposts' => -1,
        'tax_query' => array(
                array(
                    'taxonomy' => 'blog_category',
                    'field'    => 'slug',
                    'terms'    => 'update-notes',
                    'operator' => 'NOT IN'
                )
            )
        );
    $wp_query = new WP_Query($args);

    if(have_posts()):
    while ($wp_query -> have_posts()) : $wp_query -> the_post($post->ID);

    the_title();

    endwhile; endif;
    wp_reset_query();
April 29, 2016 at 3:35 pm #872243

Yuri

Hi Yuri, since the query is run by the WP_Query object you should have the resulting SQL query in the array returned. Would you mind posting that SQL query here so I can check to see what might be the issue with it?

Regards,
Yuri.

April 30, 2016 at 12:54 am #872426

yuriyY-2

So if this method doesn't works, what is the right way?

April 30, 2016 at 12:55 pm #872537

yuriyY-2

I solved the problem by myself.
I would like to share with you, here it is:

    $args = array(
        'post_type'        => 'blog_post',
        'showposts'        => -1,
        'tax_query'        => array(
                array(
                    'taxonomy' => 'blog_category',
                    'field'    => 'slug',
                    'terms'    => 'update-notes',
                    'operator' => 'NOT IN'
                )
            )
        );
    $wp_query = new WP_Query($args);

    if($wp_query->have_posts() ):
        while ($wp_query->have_posts()) : $wp_query->the_post();
            
            the_title();
            
       endwhile;
    endif;
    wp_reset_postdata();

and more this piece of code in my functions.php

    add_action( 'pre_get_posts', 'wpml_custom_query' );

    function wpml_custom_query( $query ) {
         if( is_page('blog') ) {
              $query->query_vars['suppress_filters'] = true;
         }
    }
January 11, 2018 at 2:41 pm #1481689

arvinA-2

Hello. I used the solution of add action in functions that yuriyY-2 provided and it's working for me.

For some reason the paremeter "supress_filters" is not working in WP_QUERY.

September 25, 2019 at 9:13 am #4637095

Michael

Adding the 'pre_get_posts' action works for me too... except when I have a tax_query added to my query.

Does anybody have a solution to that ?

EDIT: It works with tax_queries when combined with this solution : https://wpml.org/forums/topic/custom-taxonomy-query-in-two-languages/#post-1453955