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.

This topic contains 8 replies, has 3 voices.

Last updated by Bigul 1 month ago.

Assigned support staff: Bigul.

Author Posts
May 22, 2020 at 7:06 pm #6197787

Joe Westcott

I am trying to:
Search for English content in ACF "Link" fields or "Page Link" fields when I'm in Spanish mode.

Here's a screencast video that shows the exact problem:
hidden link (4m 17s)

Link to a page where the issue can be seen:
hidden link

I expected to see:
ACF search Results that matched my search keywords, regardless of which language I was in on the back end.

Instead, I got:
Only a list of matching results from whatever language I was in. The content in the other language failed to appear in search results.

May 25, 2020 at 8:03 am #6207657

Bigul
Supporter

Languages: English (English )

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

Hello,

Welcome to the WPML support forum. I will do my best to help you to resolve the issue.

This is how it works and custom work is required for changing this workflow. Even though if you cannot find it by search, you can still copy and paste the link to the page in the field above the search manually. That is the only workaround available for now.

We have support limitations for the customized work. It can be achieved with the help of WPML Contractors. Please refer to the following URLs for more details. Thank you for your understanding.

https://wpml.org/documentation/about-wpml-contractors/

https://wpml.org/contractors/

--
Thanks!

Bigul

May 26, 2020 at 4:23 pm #6221955

Joe Westcott

Thank you, Bigul. Your explanation is clear.

It's disappointing that WPML doesn't provide a way to access the default content when a translation exists, especially because WPML has options such as "Translatable - use translation if available or fallback to default language".

I know that that's a different option for something else. I'm pointing it out to note the inconsistency of allowing some resources to fallback to a default language, while omitting this functionality from ACFML Page Link fields.

Would it be possible to place a feature request, to allow for "Link" and "Page Link" search to allow for results in the default language, in cases where a translation does not yet exist?

I realize that there is no guarantee that WPML will agree to this feature request.

Thank you,
Joe

May 27, 2020 at 7:33 am #6226565

Bigul
Supporter

Languages: English (English )

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

Hi Joe,

Thank you for the feedback. As of now *Translatable - use translation if available or fallback to default language* option will work only on the frontend. So there are limitations to achieve this feature now.

Please visit the following URL. We have a form there for the clients to suggest new features. We will surely consider it.

https://wpml.org/suggest-a-new-feature-for-wpml/

Please check it and let me know your feedback.

--
Thanks!

Bigul

May 29, 2020 at 1:36 am #6244547

Joe Westcott

Thank you, Bigul. I've created a feature request for this ACFML default language search feature.

May 29, 2020 at 9:42 am #6248135

Konrad Karpieszuk
Supporter

Languages: English (English )

Timezone: Europe/Rome (GMT+02:00)

Helo Joe, I have replied to you directly but I will paste my answer here in case someone in the future will be looking for the same solution:

I found you can add code to your functions.php file and enable shwoing all langauge results. Please add this to your file in theme directory:

add_filter( 'pre_get_posts', 'wpml_find_all_links', 20, 1 );

function wpml_find_all_links( $wpq ) {
     $post_action = isset( $_POST['action'] ) ? $_POST['action'] : null;
     if ( 'wp-link-ajax' === $post_action ) {
          $wpq->query_vars['suppress_filters'] = true;
     }

    return $wpq;
}
June 1, 2020 at 2:31 pm #6266245

Joe Westcott

To confirm, your suggested code works!

We can now search for content in any language within Advanced Custom Fields such as the ACF Link field type and Page Link field type.

Thank you very much, Konrad.

June 1, 2020 at 8:38 pm #6268465

Joe Westcott

To build on your excellent code, Konrad, here are two additional, related features that might help people:

1. We can ensure that this ACFML-related search code runs after plugins are loaded.
2. We can enable this feature for specific languages.

So for example, maybe you have a default language like English where the content editors only want to see English content, but your secondary language editors want to see English and Spanish when searching within ACF Link fields.

I hope this helps others!

// Run functions after plugins are fully configured and loaded, e.g. WPML plugins
function after_wpml_load() {

    // When in Spanish mode
    if(ICL_LANGUAGE_CODE=='es') {

        // WPML enable multiple language results in ACF searches, e.g. when searching Link and Page Link field types
        function wpml_find_all_links( $wpq ) {
            $post_action = isset( $_POST['action'] ) ? $_POST['action'] : null;
            if ( 'wp-link-ajax' === $post_action ) {
                $wpq->query_vars['suppress_filters'] = true;
            }
            
            return $wpq;
        }
        add_filter( 'pre_get_posts', 'wpml_find_all_links', 20, 1 );

    }

}
add_action( 'init', 'after_wpml_load' );
June 5, 2020 at 9:39 am #6303199

Bigul
Supporter

Languages: English (English )

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

Hi Joe,

Thank you for the feedback and suggestions. It will help us and other forum users in the future.

Sorry for the late response. I missed your reply because of the holidays.

--
Thanks!

Bigul