Support

Account

Home Forums ACF PRO Incorrect post order with Relationship field and WPML translated page

Helping

Incorrect post order with Relationship field and WPML translated page

  • Hi there,

    I have a Relationship field set up to select and display posts from a custom post type. This works as intended for the English version, but when I duplicate the page using WPML, the translated French page displays the posts in a different order than what is selected.

    If I change the order of the items selected in the Relationship field for the translated page and save it, the order doesn’t change.

    The code to add/display the Relationship field in the template is:

    
    <?php
    			$key = get_sub_field('pg_layout_management_key');
    			$posts = get_sub_field('pg_layout_management_team');
    			if( $posts ):
    				$i = 1;
    				foreach( $posts as $post):
    					setup_postdata($post);
    					if (get_field('management_photo')):
    						$photo = get_field('management_photo');
    						$bg = $photo['url'];
    					else:
    						if($i % 2 == 0):
    							$bg = get_template_directory_uri() . '/dist/images/bg-default.jpg';
    						else:
    							$bg = get_template_directory_uri() . '/dist/images/bg-default-alt.jpg';
    						endif;
    					endif; ?>
    					<div class="visible-xs-block section-fw section-management <?php if($i % 2 == 0){ echo 'bg-alt'; }?>">
    						<div class="container">
    							<div class="row">
    								<div class="col-sm-6 col-md-5 <?php if($i % 2 == 0){ echo 'col-sm-push-6 col-md-push-7'; }?>">
    									<div class="details">
    										<div class="key"><?= $key; ?></div>
    										<h2><?php the_title(); ?></h2>
    										<div class="role"><?php the_field('management_role'); ?></div>
    										<div class="bio"><?php the_field('management_bio'); ?></div>
    									</div>
    								</div>
    							</div>
    						</div>
    					</div>
    					<div class="hidden-xs section-fw section-management <?php if($i % 2 == 0){ echo 'bg-alt'; }?>" style="background-image:url(<?= $bg; ?>)">
    						<div class="container">
    							<div class="row">
    								<div class="col-sm-6 col-md-5 <?php if($i % 2 == 0){ echo 'col-sm-push-6 col-md-push-7'; }?>">
    									<div class="details">
    										<div class="key"><?= $key; ?></div>
    										<h2><?php the_title(); ?></h2>
    										<div class="role"><?php the_field('management_role'); ?></div>
    										<div class="bio"><?php the_field('management_bio'); ?></div>
    									</div>
    								</div>
    							</div>
    						</div>
    					</div>
    				<?php $i++; endforeach;
    				wp_reset_postdata();
    			endif; ?>
    

    I followed the info on how to set up ACF to work with WPML and believe it’s all done correctly.

    Any feedback would be much appreciated.

  • Hi @kmeronuk,

    Thanks for the post.

    This issue looks like it could be stemming from some incorrect configuration in your WPML translation management page. Please note that these settings should be set before you begin creating your field groups.

    I have also noted the use of the get_sub_field() function, is the Relationship field nested within a Repeater field?

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Incorrect post order with Relationship field and WPML translated page’ is closed to new replies.