Navigation überspringen

Dieses Thema ist gelöst. Hier finden Sie eine Beschreibung des Problems und der Lösung.

Problem:
Sie haben ein deutschsprachiges ACF-Formular auf einer mehrsprachigen Webseite und möchten, dass unmittelbar nach dem Absenden des Formulars im Frontend der englischsprachige Datensatz in einer weiteren ACF-Form zum Bearbeiten angezeigt wird.
Solution:
Wir empfehlen Ihnen, den folgenden Action-Hook zu verwenden, um eine Kopie des Beitrags in einer anderen Sprache zu erstellen, sobald das Formular abgesendet wird:

add_action('acf/save_post', 'copy_post_to_all_languages', 20);<br />function copy_post_to_all_languages($post_id) {<br />    // Überprüfen, ob es sich um eine ACF-Formularübermittlung handelt<br />    // Passen Sie die bedingte Logik basierend auf Ihrer ACF-Formularkonfiguration an<br />    if (isset($_POST['acf'])) {<br />        // Holen Sie sich die Quell-Post-ID (die neu erstellte/aktualisierte Post-ID)<br />        $source_post_id = $post_id;<br />        // Holen Sie sich alle aktiven Sprachen<br />        $active_languages = apply_filters('wpml_active_languages', NULL, 'skip_missing=0');<br />        if (!empty($active_languages)) {<br />            foreach ($active_languages as $lang_code => $lang_details) {<br />                if ($lang_code !== ICL_LANGUAGE_CODE) {<br />                    // Kopieren Sie den Beitrag in jede aktive Sprache<br />                    do_action('wpml_copy_post_to_language', $source_post_id, $lang_code, $source_post_id);<br />                }<br />            }<br />        }<br />    }<br />}

Bitte beachten Sie, dass die gewünschte Funktionalität nach dem Kopieren des Beitrags als benutzerdefinierte Arbeit gilt und außerhalb des Umfangs unseres Forums liegt.

Falls diese Lösung für Sie nicht relevant ist oder veraltet erscheint, empfehlen wir Ihnen, ein neues Support-Ticket zu öffnen. Wir empfehlen Ihnen auch, die bekannten Probleme zu überprüfen, die Version der dauerhaften Lösung zu überprüfen und zu bestätigen, dass Sie die neuesten Versionen von Themes und Plugins installiert haben. Für weitere Unterstützung besuchen Sie bitte unser Support-Forum.

Dies ist das technische Support-Forum für WPML – das mehrsprachige WordPress-Plugin.

Mitlesen können alle, doch nur WPML-Kunden können hier Fragen veröffentlichen. Das WPML-Team antwortet im Forum an 6 Tagen pro Woche, 22 Stunden am Tag.

Heute stehen keine Supporter zur Arbeit im German-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Schlagwörter: 

Dieses Thema enthält 16 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Lucas Vidal de Andrade Vor 2 Monate, 1 Woche.

Assistiert von: Lucas Vidal de Andrade.

Verfasser Beiträge
Juli 2, 2024 unter 3:05 pm #15876448

markusW-55

Background of the issue:
Auf dem Frontend einer multilingualen Webseite (de/en) gibt es ein deutschsprachiges Formular (ACF), mit dem Daten erfasst werden sollen. Inzwischen habe ich herausgefunden, wie ich mit WPML den Inhalt nach dem submit auch auf englisch erzeugen kann (WPML-hook wpml_copy_post_to_language). Jetzt möchte ich, daß unmittelbar nach dem submit im frontend der englischsprachige Datensatz in einer weiteren ACF-Form zum Bearbeiten angezeigt wird.

Symptoms:
Ich brauche Hilfe, um unmittelbar nach dem submit im frontend den englischsprachigen Datensatz in einer weiteren ACF-Form zum Bearbeiten anzuzeigen.

Questions:
Wie kann ich unmittelbar nach dem submit im frontend den englischsprachigen Datensatz in einer weiteren ACF-Form zum Bearbeiten anzeigen?

Juli 2, 2024 unter 5:52 pm #15877489

Lucas Vidal de Andrade
Supporter

Sprachen: Englisch (English ) Spanisch (Español ) Deutsch (Deutsch ) Portugiesisch, Brasilien (Português )

Zeitzone: America/Sao_Paulo (GMT-03:00)

Hallo,

Können Sie mir genau zeigen, wo diese Texte erscheinen und welche es sind? Bitte senden Sie mir den Link zur Seite, damit ich das Formular direkt überprüfen kann.

Außerdem bitte ich Sie, uns Ihre Debug-Informationen zu senden. Dieser Link enthält eine Erklärung, wie das geht:
https://wpml.org/faq/provide-debug-information-faster-support/

Ich freue mich auf Ihre Rückmeldung.

Juli 3, 2024 unter 6:42 am #15880825

markusW-55

Die Seite ist noch in Entwicklung und nur localhost.

Ich verstehe nicht, wieso zur Beantwortung dieser Frage die Debug-Informationen mit umfänglichen Informationen, die ich nicht teilen möchte, benötigt wird.

Das Formular funktioniert.
Ich möchte wissen, wie ich nach dem submit den automatisch erzeugten englischsprachigen post in ein weiteres ACF-Formular zum Bearbeiten auf dem frontend laden kann.

Juli 3, 2024 unter 8:35 am #15882336

markusW-55

Here my question:
On the frontend of a multilingual website (de/en) is a German-language form (ACF) for data to be entered.
After submit, WPML-hook (wpml_cop_post_to_language) copies post in english.

Now I want the copied english post displayed in another ACF form for editing immediately after the submit.

Thanks for help!

Juli 3, 2024 unter 1:04 pm #15884513

Lucas Vidal de Andrade
Supporter

Sprachen: Englisch (English ) Spanisch (Español ) Deutsch (Deutsch ) Portugiesisch, Brasilien (Português )

Zeitzone: America/Sao_Paulo (GMT-03:00)

Hey there,

If you wish, we can continue in English. The reason I asked for the debug information, is to check:

• What WordPress version you are using;
• Which plugins you have active (solutions may vary, if you are using a page builder, a caching plugin and so on);
• Which WPML version you have;
• If you have all the necessary plugins to use ACF properly with WPML;
• Your PHP settings, specially memory (very often, the PHP settings do not meet our minimum requirements, which can impact the solution);
• Your server settings;
• Your translation settings (automatic, manual);
• Your ACF fields and settings;

I hope that answers your question. As for the access, I need to better understand the context you are working in. The solution you are asking for is very specific, that's why I asked for access. Without access, it's going to be trial and error and is probably going to take a long time to figure out the solution. If you wish, you can provide me with a copy of your website, so I can analyze and test different solutions and scenarios.

In parallel, please provide me with more details:

Here's a guide on how to do that:
https://wpml.org/faq/provide-supporters-copy-site/

I'm waiting for your feedback.

Juli 3, 2024 unter 2:01 pm #15885141

markusW-55

Hello again,
i'm still not willing to share the website, containing confidential informations.

For a working reconstruction, just have a simple ACF fieldset with a few fields, and a simple ACF form containing this fieldset.
Have a page with ACF shortcode for the form. e.g.[acfe_form name="testfrontendform"]

in functions.php:
[code]
function duplicate_post_to_secondary_language( $post_id, $mark_as_duplicate = false ) {
// Retrieve the post's element type, trid, and existing translations
$element_type = apply_filters( 'wpml_element_type', get_post_type( $post_id ) );
$trid = apply_filters( 'wpml_element_trid', null, $post_id, $element_type );
$translations = (array) apply_filters( 'wpml_get_element_translations', [], $trid, $element_type );

if ( ! $translations ) {
// Handle error or invalid values accordingly
return;
}

// Retrieve the active languages
$wpml_languages = (array) apply_filters('wpml_active_languages', [], 'orderby=id&order=desc');

foreach ( $wpml_languages as $language ) {
// Duplicate the post if no translation exists for the given language
if ( ! isset( $translations[ $language['language_code'] ] ) ) {
apply_filters(
'wpml_copy_post_to_language',
$post_id,
$language['language_code'],
$mark_as_duplicate
);
}
}
}

add_action('acf/save_post', 'duplicate_post_to_secondary_language', 20);
[/code]

Juli 3, 2024 unter 7:23 pm #15886618

Lucas Vidal de Andrade
Supporter

Sprachen: Englisch (English ) Spanisch (Español ) Deutsch (Deutsch ) Portugiesisch, Brasilien (Português )

Zeitzone: America/Sao_Paulo (GMT-03:00)

Thank you for sharing the details. I'll get a second opinion with my colleagues and will get back to you as soon as I have new information.

Juli 3, 2024 unter 7:44 pm #15886736

Lucas Vidal de Andrade
Supporter

Sprachen: Englisch (English ) Spanisch (Español ) Deutsch (Deutsch ) Portugiesisch, Brasilien (Português )

Zeitzone: America/Sao_Paulo (GMT-03:00)

Hey there,

I got a second opinion with my colleagues. This falls into custom work (custom code being written by the user) and is unfortunately out of the scope of this Forum. In our Forum, we support only standard WPML features intended to be used by end-users.

If you wish, we offer a team of specialized contractors, which can be hired in these situations:
https://wpml.org/contractors/

If you are building, or wish to build a new plugin/theme and make it compatible with WPML, you can join our Go Global program:
https://wpml.org/documentation/support/go-global-program/

You can also check our docs for developers:
https://wpml.org/documentation/support/

Juli 3, 2024 unter 8:06 pm #15886773

markusW-55

Thank you for clarification!
This "custom" code is a 1:1 copy of an example in WPML documentation https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/ (WPML hooks, Inserting Content, wpml_copy_post_to_language).

I would really appreciate a hint how to get the ids of the copied post.

Juli 4, 2024 unter 1:30 pm #15892289

Lucas Vidal de Andrade
Supporter

Sprachen: Englisch (English ) Spanisch (Español ) Deutsch (Deutsch ) Portugiesisch, Brasilien (Português )

Zeitzone: America/Sao_Paulo (GMT-03:00)

To make an exception, we would need your cooperation in providing the data we requested.

I'll escalate your code to our developers. They'll need a copy of your website to check the code in context and test different solutions. Debugging code based solely on verbal descriptions is challenging, which is why having a copy is so important for us.

If you have sensitive data that you prefer not to share, you can erase it from the copy before sharing, or you can reproduce the behavior in a test environment we provide. I've already enabled the fields to share the copy and created a test environment, which you can access here:
versteckter Link

Please choose one of these two options and let me know how you'd like to proceed.

Thank you for your understanding and cooperation.

Juli 4, 2024 unter 2:50 pm #15892898

markusW-55

Thank you very much!

On your testsite is anything ready for testing.
Frontend: /frontend-form/
admin:
site: Frontend Form
fieldset: frontendform
form: frontendform

I'm really curious to see what comes out of it.

Juli 4, 2024 unter 7:50 pm #15893899

Lucas Vidal de Andrade
Supporter

Sprachen: Englisch (English ) Spanisch (Español ) Deutsch (Deutsch ) Portugiesisch, Brasilien (Português )

Zeitzone: America/Sao_Paulo (GMT-03:00)

Thank you so much for sharing the details with us. I sent your information to our 2nd tier support, they'll take a look at your code 🙂 As soon as I hear from them, I'll get back to you.

Juli 5, 2024 unter 2:08 pm #15898914

Lucas Vidal de Andrade
Supporter

Sprachen: Englisch (English ) Spanisch (Español ) Deutsch (Deutsch ) Portugiesisch, Brasilien (Português )

Zeitzone: America/Sao_Paulo (GMT-03:00)

Hey there,

I got feedback from our devs:

This action hook allows you to create a copy of the post in a second on form submission:

add_action('acf/save_post', 'copy_post_to_all_languages', 20);

function copy_post_to_all_languages($post_id) {
    // Check if this is an ACF form submission
    // Adjust the conditional logic based on your ACF form's setup
    if (isset($_POST['acf'])) {

        // Get the source post ID (the newly created/updated post ID)
        $source_post_id = $post_id;

        // Get all active languages
        $active_languages = apply_filters( 'wpml_active_languages', NULL, 'skip_missing=0' );

        if ( ! empty( $active_languages ) ) {
            foreach ( $active_languages as $lang_code => $lang_details ) {
                if ( $lang_code !== ICL_LANGUAGE_CODE ) {
                    // Copy the post to each active language
                    do_action( 'wpml_copy_post_to_language', $source_post_id, $lang_code, $source_post_id );
                }
            }
        }
    }
}

It has been tested on a local copy by our devs. Unfortunately, what you want to achieve after that is custom work and will be outside the scope of the Forum, as I mentioned. Let me know if that helps.

Juli 5, 2024 unter 6:28 pm #15899864

markusW-55

Thank you!.
But that's just an other (may be better) way to get a post duplicated in other languages on submit.

Juli 5, 2024 unter 8:20 pm #15900116

Lucas Vidal de Andrade
Supporter

Sprachen: Englisch (English ) Spanisch (Español ) Deutsch (Deutsch ) Portugiesisch, Brasilien (Português )

Zeitzone: America/Sao_Paulo (GMT-03:00)

Yes, I understand. After that, you can store the value and use it further, but those actions depend on further development. I hope we were able to help you.

Dieses Ticket ist jetzt geschlossen. Wenn Sie ein WPML Kunde sind und Hilfe benötigen, eröffnen Sie bitte ein neues Support-Ticket.