Skip Navigation

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

Problem:
The client was experiencing an issue where translated articles were appearing in every domain's article flow instead of being restricted to their respective language domains.
Solution:
First, we ensured that WPML was active and that the front page template code included the necessary adjustments. We added

'suppress_filters' => 'false'

to the query arguments to ensure that the filters are not suppressed, which is essential for WPML to filter content by language.
Next, we navigated to WPML-> Settings-> Post Type Translation section and set the posts to "Translatable - only show translated items". This ensures that only the posts translated into the current language are displayed on the site.

If you're experiencing a similar issue, we recommend you try the following steps:
1. Activate WPML if it's not already active.
2. Ensure that your front page template code does not suppress filters by adding

'suppress_filters' => 'false'

to your query arguments.
3. Go to WPML-> Settings-> Post Type Translation and set your posts to "Translatable - only show translated items".

Please note that this solution might be irrelevant if it's outdated or not applicable to your case. If the issue persists, we highly recommend checking related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need assistance, please open a new support ticket.

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.

Tagged: 

This topic contains 27 replies, has 2 voices.

Last updated by Osama Mersal 1 year, 1 month ago.

Assisted by: Osama Mersal.

Author Posts
April 29, 2024 at 9:02 am #15575813

Osama Mersal
WPML Supporter since 02/2020

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+03:00)

Hi,

Please go to your theme files/front-page.php. Replace your wp_posts functions with wp_query. Kindly check this guide. (https://developer.wordpress.org/reference/classes/wp_query/)

Best regards,
Osama

April 29, 2024 at 9:54 am #15576233

zachariasD

Can you try that in the sandbox or do I have to do that?

April 29, 2024 at 10:13 am #15576306

Osama Mersal
WPML Supporter since 02/2020

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+03:00)

Hi,

I changed it on the sandbox site. Please check the home page. (hidden link)

Best regards,
Osama

April 29, 2024 at 11:03 am #15576678

zachariasD

Okey, we tested it on the staging and it did not work hmmm.

April 29, 2024 at 11:13 am #15576699

Osama Mersal
WPML Supporter since 02/2020

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+03:00)

Hi,

Please note that the changes I made to the sandbox are to show you how it should work, so you would need to check your custom theme's code to make it work there.

Kindly note that custom code/themes are out of our support scope. Please check our support policy. (https://wpml.org/purchase/support-policy/)

Best regards,
Osama

April 29, 2024 at 11:23 am #15576813

zachariasD

So you did not change wp_posts to wp_query in our theme and made it work?

April 29, 2024 at 11:26 am #15576818

Osama Mersal
WPML Supporter since 02/2020

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+03:00)

Hi,

I changed the sandbox site. Here is your code:

<?php
/**
 * The template for displaying archive pages.
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package nsm
 */
get_header();

$page_id = get_the_ID();

// Current page we are on
$current_page   = get_query_var( 'page' ) ? get_query_var( 'page' ) : 1;

// Posts per page
$posts_per_page = 36;

// Total number of posts
$total_posts    = wp_count_posts()->publish;

// Loop offset
$offset         = ( $current_page - 1 ) * $posts_per_page;

// Loop arguements
$args = array(
    'post_type'         => 'post',
    'posts_per_page'    => $posts_per_page,
    'offset'            => $offset,
);

$ts_args = array(
    'post_type'         => 'post',
    'posts_per_page'    => 3,
);

if( $sticky_posts = get_option('sticky_posts') ){
    $ts_args['post__in'] = $sticky_posts;
}else{

    $ts_args['meta_key'] = 'post_views';
    $ts_args['orderby'] = 'meta_value_num';
    $ts_args['order'] = 'DESC';
    $ts_args['date_query'] = array(
        array(
            'after' => strtotime( 'last Thursday' ),
        ),
    );
}

if( $excluded_cat = get_field('hidden_category', 'options') ){
    $args['category__not_in']       =  [ $excluded_cat ];
    $ts_args['category__not_in']    =  [ $excluded_cat ];
} 

// Total number of pages
$total_pages = ceil( $total_posts / $posts_per_page );
?>

<div class="py-15">

	<div class="container">

        <div class="row kimura-content-area">

            <div class="kimura-content-wrap px-10">

                <!-- Top Splash -->
                <?php
                $ts_posts = get_posts( $ts_args );
                if( $ts_posts ){
                ?>
                <div class="text-center mb-20 w-100">
                    <?php if( function_exists('the_ad_placement') ) { the_ad_placement('980-ads'); } ?>
                </div>
                <div class="post-top_splash">
                    <div class="row top_splash">
                    <?php foreach( $ts_posts as $key => $post ){ ?>
                        <div class="md-4 post-item-<?php echo $key ?> sm-4">
                            <?php get_template_part( 'template-parts/post/top_splash' ); ?>
                        </div>
                    <?php } ?>
                    </div>
                </div>
                <?php wp_reset_postdata(); ?>
                <?php } ?>

                <div class="text-center mb-20 w-100">
                    <?php if( function_exists('the_ad_placement') ) { the_ad_placement('980-ads'); } ?>
                </div>

                <!-- Content -->
                <?php if( !is_paged() ){ ?>
                <div class="entry-content front-page_content tc-d mb-20 bg-p px-20 py-20">
                    <?php echo get_the_content( null, false, $page_id ); ?>
                </div>
                <?php } ?>
               
                <!-- Loop A -->
                <?php 
                // The posts
                $posts = get_posts( $args );
                if ( $posts ){
                ?>

                <?php if( $loop_a = array_slice( $posts, 0, 16 ) ){ ?>
                <div class="row post-loop_a">
                    <div class="kimura-content-wrap-inner px-10">
                    <?php foreach( $loop_a as $key => $post ){ ?>
                        <div class="post-item post-item-<?php echo $key ?>">
                            <?php get_template_part( 'template-parts/post/layouts/layout-1' ); ?>
                        </div>
                        
                        <?php
						// we are leaving this increase we needed to change for mobile and desktop
						if( wp_is_mobile() ){
							if($key % 2 == 1 && $key != count($loop_a) - 1){
								echo '<div class="text-center mb-20 w-100">';
								if( function_exists('the_ad_placement') ) { the_ad_placement('640-ads'); }
								echo '</div>';
                        	}
						}else{
							if( $key % 2 == 1 && $key != count($loop_a) - 1){
								echo '<div class="text-center mb-20 w-100">';
								if( function_exists('the_ad_placement') ) { the_ad_placement('640-ads'); }
								echo '</div>';
                        	}
						}
                        ?>
                    <?php } ?>
                    
                    <?php wp_reset_postdata(); ?>
                    </div>
                    <?php if( is_active_sidebar('sidebar-2') ){ ?>
                    <div class="kimura-sidebar sidebar-2 mb-20 f-1 px-10 sidebar-sticky d-none d-md-block">
                        <div>
                            <?php dynamic_sidebar( 'sidebar-2' ); ?>
                        </div>
                    </div>
                    <?php } ?>
                </div>
                <?php } ?>

                <!-- Loop B -->
                <?php if( $loop_b = array_slice( $posts, 16 ) ){ ?>
                <div class="row post-loop_b">
                    
                    <?php foreach( $loop_b as $key => $post ){ ?>

                        <?php
                        if( wp_is_mobile() ){
                            if( $key % 2 == 0 ){
                                echo '<div class="text-center mb-20 w-100 px-10">';
                                if( function_exists('the_ad_placement') ) { the_ad_placement('980-ads'); }
                                echo '</div>';
                            }
                        }else{
                            if( $key % 4 == 0 ){
                                echo '<div class="text-center mb-20 w-100 px-10">';
                                if( function_exists('the_ad_placement') ) { the_ad_placement('980-ads'); }
                                echo '</div>';
                            }
                        }
                        ?>

                        <div class="post-item post-item-<?php echo $key ?> sm-6">
                            <?php get_template_part( 'template-parts/post/layouts/layout-1' ); ?>
                        </div>

                        <?php
                        if( $key == count($loop_b) - 1 ){
                            echo '<div class="text-center mb-20 w-100 px-10">';
                            if( function_exists('the_ad_placement') ) { the_ad_placement('980-ads'); }
                            echo '</div>';
                        }
                        ?>

                    <?php } ?>
                    <?php wp_reset_postdata(); ?>
                </div>
                <?php } ?>

                <?php } ?>

            </div>

            <?php if( is_active_sidebar('sidebar-1') ){ ?>
            <div class="kimura-sidebar f-1 px-10 mb-20 d-none d-lg-block">
                <?php dynamic_sidebar( 'sidebar-1' ); ?>
            </div>
            <?php } ?>

        </div>

        <?php if( $posts ){ ?>

        <?php if( $current_page == 1 ){ ?>
        <div class="d-flex ai-c jc-e mt-20">
            <a id="page-next" class="btn btn-primary w-100 w-sm-auto" href="<?php echo home_url() ?>/page/2/">Nästa sida</a>
        </div>
        
        <div class="kimura-sponsors my-20 text-center">
            <span class="d-i-block bg-p tc-d fw-sb fs-14 px-10 py-5">Samarbetspartners</span>
        </div>
        <div class="text-center text-sm-left">
            <a class="mr-5 mb-5 d-i-block" href="<em><u>hidden link</u></em>"><img src="<em><u>hidden link</u></em>" title="Matspar index logo" width="300" height="60"></a>
            <a class="mr-5 mb-5 d-i-block" href="<em><u>hidden link</u></em>"><img src="<em><u>hidden link</u></em>" title="Unibet index logo" width="300" height="60"></a>
            <a class="mr-5 mb-5 d-i-block" href="<em><u>hidden link</u></em>"><img src="<em><u>hidden link</u></em>" title="Pluto index logo" width="300" height="60"></a>
            <a class="mr-5 mb-5 d-i-block" href="<em><u>hidden link</u></em>"><img src="<em><u>hidden link</u></em>" title="Bettingcom index logo" width="300" height="60"></a>
            <a class="mr-5 mb-5 d-i-block" href="<em><u>hidden link</u></em>"><img src="<em><u>hidden link</u></em>" title="sportpanelen" alt="sportpanelen" width="300" height="60"></a>
            <a class="mr-5 mb-5 d-i-block" href="<em><u>hidden link</u></em>"><img src="<em><u>hidden link</u></em>" title="mmabetz" alt="mmabetz" width="300" height="60"></a>
        </div>
        <?php }else{ ?>
        <?php Nsm_Helper::pagination( [ 'type' => 'post', 'total' => $total_pages ], $current_page ); ?>
        <?php } ?>

        <?php wp_reset_postdata(); ?>
        <?php } ?>

    </div>

</div>

<?php get_footer(); ?>

and here is the current code

<?php
/**
 * The template for displaying archive pages.
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package nsm
 */
get_header();

$page_id = get_the_ID();

// Current page we are on
$current_page = max(1, get_query_var('paged'));

// Posts per page
$posts_per_page = 36;

// Query for regular posts
$args = array(
    'post_type'      => 'post',
    'posts_per_page' => $posts_per_page,
    'paged'          => $current_page,
);

$main_query = new WP_Query($args);

// Query for top splash posts
$ts_args = array(
    'post_type'      => 'post',
    'posts_per_page' => 3,
);

if ($sticky_posts = get_option('sticky_posts')) {
    $ts_args['post__in'] = $sticky_posts;
    $ts_args['orderby'] = 'post__in';
} else {
    $ts_args['meta_key'] = 'post_views';
    $ts_args['orderby'] = 'meta_value_num';
    $ts_args['order'] = 'DESC';
    $ts_args['date_query'] = array(
        array('after' => '1 week ago'),
    );
}

if ($excluded_cat = get_field('hidden_category', 'options')) {
    $args['category__not_in'] = $ts_args['category__not_in'] = [$excluded_cat];
} 

$ts_query = new WP_Query($ts_args);
?>

<div class="py-15">
    <div class="container">
        <div class="row kimura-content-area">
            <div class="kimura-content-wrap px-10">

                <!-- Top Splash -->
                <?php if ($ts_query->have_posts()) : ?>
                    <div class="text-center mb-20 w-100">
                        <?php if (function_exists('the_ad_placement')) the_ad_placement('980-ads'); ?>
                    </div>
                    <div class="post-top_splash">
                        <div class="row top_splash">
                            <?php while ($ts_query->have_posts()) : $ts_query->the_post(); ?>
                                <div class="col-md-4 post-item-<?php echo $ts_query->current_post; ?> col-sm-4">
                                    <?php get_template_part('template-parts/post/top_splash'); ?>
                                </div>
                            <?php endwhile; wp_reset_postdata(); ?>
                        </div>
                    </div>
                <?php endif; ?>

                <div class="text-center mb-20 w-100">
                    <?php if (function_exists('the_ad_placement')) the_ad_placement('980-ads'); ?>
                </div>

                <!-- Main Content Loop -->
                <?php if ($main_query->have_posts()) : ?>
                    <?php while ($main_query->have_posts()) : $main_query->the_post(); ?>
                        <div class="post-item post-item-<?php echo $main_query->current_post; ?>">
                            <?php get_template_part('template-parts/post/layouts/layout-1'); ?>
                            <?php if (($main_query->current_post % 2 == 1) && !$main_query->is_last()) : ?>
                                <div class="text-center mb-20 w-100">
                                    <?php if (function_exists('the_ad_placement')) the_ad_placement('640-ads'); ?>
                                </div>
                            <?php endif; ?>
                        <?php endwhile; ?>
                        <!-- Pagination Logic -->
                        <?php echo paginate_links(array('total' => $main_query->max_num_pages)); ?>
                        <?php wp_reset_postdata(); ?>
                    <?php endif; ?>

                </div>
            </div>

            <?php if (is_active_sidebar('sidebar-1')) : ?>
                <div class="kimura-sidebar f-1 px-10 mb-20 d-none d-lg-block">
                    <?php dynamic_sidebar('sidebar-1'); ?>
                </div>
            <?php endif; ?>
        </div>
    </div>
</div>

<?php get_footer(); ?>

Best regards,
Osama

April 30, 2024 at 6:12 am #15579294

zachariasD

Dosent seem to work. This issue isnt new:

hidden link

Do you have any colleagues that have faced the same issue in the support?

April 30, 2024 at 6:22 am #15579317

Osama Mersal
WPML Supporter since 02/2020

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+03:00)

Hi,

Please check this reply. (https://wpml.org/forums/topic/query-posts-return-all-language/#post-14172683)

Also, please check this guide. (https://wpml.org/documentation/support/debugging-theme-compatibility/#issue-wp_queryargs-or-get_postsargs-doesnt-filter-out-correct-posts-ids-for-the-current-language)

Best regards,
Osama

April 30, 2024 at 6:26 am #15579330

zachariasD

Yes

but it dosent only appear on the index page, all URL's all tha pages appear under all domains.

April 30, 2024 at 6:50 am #15579410

Osama Mersal
WPML Supporter since 02/2020

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+03:00)

Hi,

On your staging site, WPML was not active, and the front page template code was not changed.

However, I added the 'suppress_filters' => 'false' to your args. (Kindly check the attached screenshot)

Please check if the translated posts appear on the home page.

Best regards,
Osama

2024-04-30_09-45-48.jpg
April 30, 2024 at 7:06 am #15579494

zachariasD

Now it works, the translations show on each page and now double anymore, but all old posts (that are not translated) still appear on each site. How do we solve this?

April 30, 2024 at 7:13 am #15579556

Osama Mersal
WPML Supporter since 02/2020

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+03:00)

Hi,

In order to show the posts/pages in only the current language, please go to WPML-> Settings-> Post Type Translation section and set the posts to "Translatable - only show translated items".

I did that on your staging site. Please check the English home page. (hidden link)

Best regards,
Osama

May 3, 2024 at 6:28 am #15589538

zachariasD

Thank you for the help! Everything is solved now