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.

Please make sure to update to WPML to the latest and check our list of Known Issues before reporting

This topic contains 6 replies, has 2 voices.

Last updated by Jorgen Lindstrom 1 month ago.

Assigned support staff: Riffaz.

Author Posts
February 18, 2020 at 8:37 pm #5518543

Jorgen Lindstrom

I have a box on my page where I show when the next concert with this choir should be. As it is now, both the Swedish and the English language versions are displayed side by side on both the Swedish and the English side.

hidden link

February 19, 2020 at 6:12 am #5520605

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

Thank you for contacting WPML support.

This really depends on how that widget works.
Is that a plugin?
Does it come from the theme?
Does that widget has any option to choose languages?

I could not find your theme on our compatibility list: https://wpml.org/documentation/theme-compatibility/
Anyhow, we can help you to create a workaround for this upon the details you provide.

Let me know.

Regards,
Riffaz.

February 19, 2020 at 1:55 pm #5524427

Jorgen Lindstrom

Hello and thank you for your answer.

Is that a plugin? No I wrote it myself.
Does it come from the theme? No
Does that widget has any option to choose languages? No

Jorgen

February 20, 2020 at 11:41 am #5532523

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

Then it's a custom work and we have to check how do you fetch the data based on the language.
We can create the workaround for this only if we do not have to edit a lot of your code lines.
We need a test site to check this.

Do you have a test with your code and this widget?
So we can troubleshoot and try to create a workaround.

Regards,

February 20, 2020 at 2:54 pm #5534063

Jorgen Lindstrom

It looks like this or do you need something else?

<?php
/**
 * Template Name: Startsida
 *
 * Template for displaying a page just with the header and footer area and a "naked" content area in between.
 * Good for landingpages and other types of pages where you want to add a lot of custom markup.
 *
 * @package understrap
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}


setlocale(LC_TIME, "sv_SE"); 
$today = date( 'Ymd' );?>

<section>
	<div class="container">
		<div class="row">


			<?php 
			$posts = get_posts(array(
			'post_type'			=> 'konserter',
			'posts_per_page'	=> 1,
			'meta_query' => array(
				'key' => 'stop-datum',
				'compare' => '>=',
				'value' => $today)
		
			));
			
			if($posts):
 		?>

			<?php foreach( $posts as $post ){ 
	setup_postdata( $post ); ?>

			<div class="col-12 col-md-6 gray post-detail">
				<div class="date-box">
					<?php $date = strtotime(get_field('start-datum')); ?>
					<strong class="date">
						<?php echo strftime('%d', $date); ?>
					</strong>
					<div class="sub-detail">
						<strong class="month">
							<?php echo strftime('%B', $date); ?>
						</strong>
						<p>
							<?php the_field('start-tid'); ?>
							<?php the_field('plats'); ?>
						</p>
					</div>
				</div>


				<?php

				//Fler datum med samma produktion ruta 1 grey
				if ( have_rows( 'ytterligare' ) ): ?>

				<div class="recurrent-date-box">

					<?php while ( have_rows('ytterligare') ) : the_row();?>



					<?php $date = strtotime(get_sub_field('startdatum')); ?>
					<div class="sub-detail">
						<strong class="date">
							<?php echo strftime('%d', $date); ?>
						</strong>
						<strong class="month">
							<?php echo strftime('%b', $date); ?>
						</strong>
						<?php the_sub_field('starttid'); ?>
						<?php the_sub_field('plats'); ?>
					</div>


					<?php

					endwhile;
					?>

				</div>
				<!--end recurrent-date-box-->

				<?php else :

													// no rows found

												endif;

												?>


				<div class="detail">
					<h2>
						<?php the_title(); ?>
					</h2>
					<div class="text sameHeight">
						<p>
							<?php the_content(); ?>
						</p>
					</div>
				</div>
			</div>

			<?php } endif; ?>

			<!--//////////////////////////////////-->


			<?php 			
				$posts = get_posts(array(
				'post_type'			=> 'konserter',
				'posts_per_page'	=> 1,
				'meta_query' => array(
					'key' => 'stop-datum',
					'compare' => '>=',
					'value' => $today),
				'offset' => 1
		
				));

if( $posts ): 
			?>

			<?php foreach( $posts as $post ){ 
		setup_postdata( $post );
		
		?>

			<div class="col-12 col-md-6 black post-detail">
				<div class="date-box">
					<?php $date = strtotime(get_field('start-datum')); ?>
					<strong class="date">
						<?php echo strftime('%d', $date); ?>
					</strong>
					<div class="sub-detail">
						<strong class="month">
							<?php echo strftime('%B', $date); ?>
						</strong>
						<p>
							<?php the_field('start-tid'); ?>
							<?php the_field('plats'); ?>
						</p>
					</div>
				</div>


				<?php
				//Fler datum med samma produktion ruta 2 Black
				if ( have_rows( 'ytterligare' ) ): ?>

				<div class="recurrent-date-box">
					<?php while ( have_rows('ytterligare') ) : the_row();?>



					<?php $date = strtotime(get_sub_field('startdatum')); ?>
					<div class="sub-detail">
						<strong class="date">
							<?php echo strftime('%d', $date); ?>
						</strong>
						<strong class="month">
							<?php echo strftime('%b', $date); ?>
						</strong>
						<?php the_sub_field('starttid'); ?>
						<?php the_sub_field('plats'); ?>
					</div>


					<?php endwhile;?>

				</div>
				<!--end recurrent-date-box-->

				<?php else :

													// no rows found

												endif;

												?>


				<div class="detail">
					<h2>
						<?php the_title(); ?>
					</h2>
					<div class="text sameHeight">
						<p>
							<?php the_content(); ?>
						</p>
					</div>




				</div> <button class="btn btn-outline-light" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">FLER KONSERTDATUM</button>
			</div>
			<!--Black-->
			<?php } endif; ?>
		</div>
		<!--row-->
	</div>
</section>



<!--FLER KONSERTDATUM COLLAPS-->
<div class="collapse" id="collapseExample">
	<section>
		<div class="container">
			<div class="row gray">

				<?php
				$posts = get_posts( array(
					'post_type' => 'konserter',
					'posts_per_page' => 6,
					'meta_query' => array(
						'key' => 'stop-datum',
						'compare' => '>=',
						'value' => $today),
					'offset' => 2

				) );

				if ( $posts ):
					?>

				<?php foreach( $posts as $post ){ 
		setup_postdata( $post );
		
		?>
				<div class="col-12 col-md-6 gray collaps-post-detail">
					<div class="date-box">
						<?php $date = strtotime(get_field('start-datum')); ?>
						<strong class="date">
							<?php echo strftime('%d', $date); ?>
						</strong>
						<div class="sub-detail">
							<strong class="month">
								<?php echo strftime('%B', $date); ?>
							</strong>
							<p>
								<?php the_field('start-tid'); ?>
								<?php the_field('plats'); ?>
							</p>
						</div>
					</div>
					<div class="collaps-detail">
						<h2>
							<?php the_title(); ?>
						</h2>
					</div>
				</div>

				<?php } endif; ?>

				<?php wp_reset_postdata();?>
			</div>
		</div>
	</section>
</div> <!--Collaps-->

<?php get_footer();?>

February 23, 2020 at 5:56 am #5548261

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

This is a pure custom work.
You are fetching all the 'konserter' post type without considering the language.

When creating and editing your theme’s PHP templates, you can list posts by using the get_posts function. By default, this function will return all posts for every language. To return only posts for the current language, you have two options. First is to set the 'suppress_filters' of the get_posts function to false. The second, preferred option is to return posts using the query_posts function instead.

If you choose to use the get_posts function, consider the following code snippet as an example:

$args = array( // all your other arguments here 'suppress_filters' => false );
$posts_array = get_posts( $args );

The issue has been fixed here: https://wpml.org/forums/topic/get_posts-by-language/
Please refer that.

Regards,

February 24, 2020 at 8:35 am #5552203

Jorgen Lindstrom

My issue is resolved now. Thank you!