Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache returns wrong translation for select choice #244

Open
slackday opened this issue May 13, 2024 · 2 comments
Open

Cache returns wrong translation for select choice #244

slackday opened this issue May 13, 2024 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@slackday
Copy link

This might be complex but I would like to know more how acf:cache works so I can look for a solution. It seems the wrong value is returned for "choices" when page is translated using wpml.

I have defined the choices field with addSelect like this

            ->addSelect('gender', [
                'label' => 'Kön',
                'choices' => [
                    'mare' => _x('Mare', 'Gender select', 'sage'),
                    'stallion' => _x('Stallion', 'Gender select', 'sage'),
                    'gelding' => _x('Gelding', 'Gender select', 'sage'),
                ],
                'default_value' => 'stallion',
                'wpml_cf_preferences' => 1,
            ])

wpml_cf_preferences = 1 is so that the value of the select is copied to the translation.

I return the value in my template like this

        $gender = get_field('gender', $post_id);
        if (! empty($gender)) {
            $gender_object = get_field_object('gender');
            $gender = $gender_object['choices'][$gender] ?? $gender;
            $details['gender'] = [
                'label' => __('Gender', 'sage'),
                'value' => $gender,
            ];
        }

This works but if I change language on my site the untranslated value is returned.

If I run wp acorn acf:clear the correct value is returned. But running wp acorn acf:cache gives the wrong value again.

@Log1x
Copy link
Owner

Log1x commented May 13, 2024

The cache stuff converts everything to JSON here when writing the blocks from the Manifest here.

I'm sorry, but I do not use WordPress for any multi-lang projects so I'll need someone else to take lead when it comes to fixing issues like this. 🤗

@Log1x Log1x added the help wanted Extra attention is needed label May 13, 2024
@slackday
Copy link
Author

Understood. And this is an edge case. Thanks for showing how caching works. I will have a look if this can be solved in a clean way. WPML uses a "glue" plugin called WPML ACF for handling fields in different languages. I know that when using this plugin and creating field and saving them as json in acf-json folder they are separated by a lang subfolder. Maybe something similar needs to happen here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants