Skip Navigation

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

Problem:
The client's custom post type field is not displaying translations on the frontend.
Solution:
We recommend ensuring that if you are selecting a taxonomy or a custom post type in your code, you must also select the translated version of that taxonomy or custom post type. If the slug is translated for the post type or taxonomy, but not updated in your code, this could be the reason why the translations are not appearing on the frontend.

If this solution does not apply to your situation, or if it seems outdated, we encourage you to open a new support ticket. We also highly recommend checking the related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. For further assistance, please visit our support forum.

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 4 replies, has 2 voices.

Last updated by Lauren 10 months ago.

Assisted by: Lauren.

Author Posts
January 23, 2024 at 4:13 pm

gustavG-2

Custom post type field not showing translations on the frontend

January 23, 2024 at 4:57 pm
January 23, 2024 at 5:45 pm #15218485

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-05:00)

Please allow admin access to the site so that I can review templates and ACF settings. Once that is done, let me know and I'll be happy to further troubleshoot.

January 24, 2024 at 2:00 pm #15222179

gustavG-2

Hello!

You now have admin access and access to ACF settings. I am not sure what you mean by review templates though.

January 25, 2024 at 7:50 am #15224670

gustavG-2

So I noticed one thing while testing the ACF Block coworker on these two pages:
hidden link
hidden link

Depending on if I choose to show coworkers from a specific department or show all coworkers, the translation is displayed on frontend. But when I select the option Show specific coworker the translation don't display.

I attach a screenshot of the field group for the block that is used on these pages and the page Styrelse (Board) that we first discovered the problem on.

I am still trying to figure it out. Can you see anything?

And this is the code template for the block:

<?php
/**
* The template for the coworker block
*
* @package Gital Blocks
*/

// Defining settings.
$settings = array();
$settings['department-toggle'] = get_field( 'selectDepartment' );
$settings['hide_images'] = get_field( 'hide_images' );
$settings['hide_description'] = get_field( 'hide_description' );
$settings['additional-classes'] = ( isset( $block['className'] ) ? ' ' . $block['className'] : '' );
$settings['additional-classes'] .= ( get_field( 'margin' ) ? ' g-margin-bottom' : '' );
if ( 'card' === get_field( 'style' ) || ! get_field( 'style' ) ) {
$settings['additional-classes'] .= ' g-coworkers--card';
} else {
$settings['additional-classes'] .= ' g-coworkers--archive';
}
$setting['args'] = array(
'post_type' => 'coworkers',
'fields' => 'id',
'suppress_filters' => false,
'posts_per_page' => -1,
'orderby' => 'menu_order title',
'order' => 'ASC',
);

// Defining the arguments for the query.
if ( 'department' === $settings['department-toggle'] ) {
$settings['department'] = get_field( 'department' );
$setting['args']['tax_query'] = array(
array(
'taxonomy' => 'department',
'field' => 'term_id',
'terms' => $settings['department'],
),
);
$persons = get_posts( $setting['args'] );
} elseif ( 'all' === $settings['department-toggle'] ) {
$persons = get_posts( $setting['args'] );
} else {
$persons = array();
foreach ( get_field( 'persons' ) as $person ) {
$persons[] = $person['person'];
}
}

// Rendering the element.
if ( ! empty( $persons ) ) {
?>
<div class="g-block g-coworkers<?php echo $settings['additional-classes']; ?>">
<?php foreach ( $persons as $person ) { ?>
<div class="g-coworkers__item g-coworker">
<?php
if ( ! $settings['hide_images'] ) {
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $person ), 'thirdpage' )[0];
$alttext = get_post_meta( get_post_thumbnail_id( $person ), '_wp_attachment_image_alt', true );
?>
<img class="g-coworker__portrait" src="<?php echo $image; ?>" alt="<?php echo $alttext; ?>">
<?php } ?>
<div class="g-coworker__text-container">
<h4 class="g-coworker__title"><?php echo esc_html( get_the_title( $person ) ); ?></h4>
<hr>
<?php
if ( $occupation = get_field( 'occupation', $person ) ) {
?>
<h5 class="g-coworker__occupation"><?php echo $occupation; ?></h5>
<?php
}
?>
<?php
if ( get_field( 'mail', $person ) && is_email( get_field( 'mail', $person ) ) ) {
$mail_href = esc_attr( get_field( 'mail', $person ) );
$mail_array = explode( '@', $mail_href );
$mail_show = '<nobr>' . $mail_array[0] . '</nobr><nobr>@' . $mail_array[1] . '</nobr>';
?>
">
<?php
}
if ( get_field( 'phone', $person ) ) {
?>
<p class="g-h5 g-coworker__phone"><?php echo esc_html( gital_library\g_phone( get_field( 'phone', $person ) ) ); ?></p>
<?php
}
if ( ! $settings['hide_description'] && get_field( 'description', $person ) ) {
?>
<p class="g-coworker__description"><?php echo wp_kses( get_field( 'description', $person ), 'post' ); ?></p>
<?php
}
?>
</div>
</div>
<?php } ?>
</div>
<?php
}

Screenshot 2024-01-25 at 08-46-29 Redigera fältgrupp ”Medarbetare” ‹ Eleda — WordPress.png
January 25, 2024 at 10:05 pm #15228382

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-05:00)

Make sure that if you are selecting a taxonomy, if you have translated it, you will need to select the translated taxonomy in your code. Same with the post type - if the slug is translated in either the post type, a taxonomy, etc, but not in your code, then this could explain why the post translations are not showing.