adrienR-5
<b>Background of the issue: </b>
I'm trying to fetch the number of posts from a specific taxonomy.
This is my current function code:
[...]
$args = array(
'post_type' => 'actualite-franchise',
'fields' => 'ids',
'posts_per_page' => 1,
'no_found_rows' => false,
'post_status' => 'publish',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'type-actualite',
'field' => 'slug',
'terms' => 'short-news'
),
array(
'taxonomy' => 'franchise_category',
'field' => 'term_id',
'terms' => $current_terms, /* $current_terms = array(953) in this case */
'operator' => 'IN',
)
),
'ignore_sticky_posts' => 1,
'suppress_filters' => false,
);
$the_query = new WP_Query($args);
return $the_query->found_posts;
}
<b>Symptoms: </b>
The issue is that it is returning me the total number of those posts from this custom taxonomy but for my default language.
<b>Questions: </b>
How can I get the total number of posts of 'nl-be' (Dutch Belgium) for example if I visit the page in WPML current language nl-be?
adrienR-5
It seems that the documentation is wrong, we need to set suppress_filters to true in order to fetch the posts within the current language.
This helped me: https://wordpress.stackexchange.com/a/406763
Mateus Getulio
Supporter
Languages:
English (English )
Portuguese (Brazil) (Português )
Timezone:
America/Sao_Paulo (GMT-03:00)
Hello Adrien,
I'm glad to know that the issue seems fixed now, thank you for sharing the solution.
I checked it and there were other times where we recommended setting suppress_filters to true in order to avoid other filters from changing the result of the wp query:
https://wpml.org/forums/topic/how-to-make-wordpress-search-posts-and-pages-in-all-language/
https://wpml.org/forums/topic/search-results-from-other-languages-not-displaying/
Can you point me to the documentation that needs to be edited? We'll check it and make the needed changes.
Thank you,
Mateus
adrienR-5
Hello Mateus,
Hope you're doing well
Here's the documentation that would need to be edited I think: https://wpml.org/documentation/support/debugging-theme-compatibility/#issue-wp_queryargs-or-get_postsargs-doesnt-filter-out-correct-posts-ids-for-the-current-language