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.

Our next available supporter will start replying to tickets in about 11.37 hours from now. Thank you for your understanding.

This topic contains 19 replies, has 3 voices.

Last updated by laura-dY 5 months, 2 weeks ago.

Assigned support staff: Bruno Kos.

Author Posts
April 19, 2019 at 1:47 pm #3646151

laura-dY

I created a custom post type: "experts" in a plugin. I also created an options page within the custom post type. I need to be able to select which experts show up on the archive page and order the experts by a custom order. To do this, I created an ACF Relationship field for the experts on the options page. This way, you can pull in as many experts as you want and order them with drag and drop.

I used a pre_get_posts function to restrict the experts to those selected on the settings page and set the order.

The issue is on the experts settings page. When I am in German (the default language) I see all of the experts once (German translation) and add them in the order I want. They show up properly on the front end. So far, so good.

When I switch to the English front end nothing is there. Ideally I'd like to be able to set the experts once and have it apply to all languages. If I go to the settings page in English, I see all the German experts there (I can only tell because I temporarily changed their names so I can differentiate.) I would have to delete them and re-add the English versions to get them to show up on the front end. Since what I want to show up won't change with language and we may have several languages, I want to be able to add the experts only once and have those experts in the relevant translation show up in each language. Otherwise we risk setting different languages in different order or missing one. It just adds a lot of room for error (not to mention extra work) if we have to repeat this action for every language. Is it possible to set this up so that I only have to add the experts in once and it applies to all languages?

A little more information: I used the PHP Generator to create the relationship field so that I can include it in the plugin instead of the theme. I tried all the translation settings: translate, do not translate, copy and copy once but it doesn't seem to change the behavior.

Thanks!

April 22, 2019 at 4:51 pm #3657099

Lauren
Supporter

Languages: English (English )

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

Thank you for contacting WPML support. I'll be happy to help you with this.

You should be able to accomplish what you are trying by setting the fields to copy. Please review the documentation here: https://wpml.org/documentation/related-projects/translate-sites-built-with-acf/

Also, after our latest update, you need to set individual fields, so please visit the field group in the secondary language and make sure that the fields are set correctly there. Lastly, check to see if your field groups are set according to the documentation in WPML -> Settings -> Post Types.

If everything is set correctly, and you saved the individual fields as Copy, let me know and I will be happy to continue troubleshooting.

April 23, 2019 at 6:56 pm #3667039

laura-dY

I originally tried to duplicate the Custom Field Group so that I could translate the interface, but was having trouble so I deleted that. According to the ACF instructions from your link, you only need to duplicate the Field Group if you want to translate the interface. Ideally, I'd like to, but I wanted to see if I could get this working, so I thought I'd try this first.

So in this case there is no secondary language field group to set to "copy". The original is already set to "copy". When you say "saved the individual fields as Copy" what exactly do you mean by individual fields? It is only one field (relationship). That field is set to "copy".

Field Groups in WPML -> Settings -> Post Types are set to translate.

April 24, 2019 at 1:12 am #3668035

Lauren
Supporter

Languages: English (English )

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

Please try duplicating the field group where this relationship field is created. Then, you should be able to set the field to copy and let me know if it works correctly.

April 24, 2019 at 7:23 am #3669813

laura-dY

This doesn't fix the issue. I duplicated the field group and set both to copy. Now I do only get one interface showing up on the settings page, and I get the correct posts showing up on the left side of the relationship field in each language, however both languages show up on the right side (the selected posts) in both languages (so there are double posts on the right side in both languages). Is there anyway to avoid that?

If we can get this to work properly, I'd still like to address the possibility of using the PHP generated code in the plugin instead of the standard Field Groups in the theme. (I removed the PHP generated code for now).

April 24, 2019 at 2:56 pm #3674403

Lauren
Supporter

Languages: English (English )

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

To best troubleshoot the issue, please make a snapshot of your site using the Duplicator plugin: https://wordpress.org/plugins/duplicator/. This will allow me to try and duplicate the error so that I can run further tests without interrupting your live site.

Once the snapshot is complete, either upload the snapshot ZIP file and the installer.php file to a file sharing service such as Dropbox (and share the link in your reply) or right click the Duplicator links in your wp-admin and paste in your reply.

Please note: It is important to reduce the size of the package so please exclude some paths like /cache or /uploads and also exclude archives and media files.

I will also need the username and password of an account that was created BEFORE creating the duplicator package.

I will enable the next reply to be private so only you and I have access to it!

April 25, 2019 at 5:23 pm #3684671

Lauren
Supporter

Languages: English (English )

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

Thanks for sending the files. I think the problem was coming from the settings on Experts, not on the actual field group. In order to not have to create each expert twice, please go to WPML -> Settings and scroll to the Post Types section. Set Experts to "Translatable or Fallback to default". Now, when you visit the Experts -> Options page, you see all of the experts on the backend and on the frontend. So, you will not have to translate the Experts, but you will be able to select them for either language.

Please try this on your live site and let me know if you need any further assistance.

April 26, 2019 at 9:23 am #3689169

laura-dY

Sorry, this doesn't change anything for me and I am not sure what you mean by "not having to translate the experts". The experts should be translated and show up on the corresponding language page. The only thing that shouldn't be translated is which experts show up on the page and in which order. This is what I am using the ACF Experts Order Relationship field for.

After making this change, I don't see any change at all. On the experts options page, the left side still shows the experts in both languages and when I select them (the german ones for the german language) they move to the right side as selected. When I then switch over to the english settings page, those are still set and so the german experts show up on the english page on the front end. If I delete them from selected and add the english ones, this changes the german side as well and then only the english experts show up in both languages.

I want the english experts translation to show up on the english page and the german experts translation to show up on the german page, but (ideally) I'd like to select the experts once and order them once since the selection and order are the same for both languages. Is this possible?

April 26, 2019 at 9:15 pm #3693311

Lauren
Supporter

Languages: English (English )

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

Thanks for clarifying. I think I understand and was able to reproduce on my test install. Here's what I did:

1. Create a new expert in German
2. Translate the expert to English
3. In Experts -> Settings, add the German expert to the list
4. WHen I go to Expert -> settings in English, I still see that the English translation could be added, and I see that the German expert is added to the list.

You would like that the English translation shows in the list of the English settings, and the German expert does not show at all. Is this correct?

Additionally, if you reorder the experts, you would like the order to change in both languages.

I am not sure if this is possible but I am going to discuss with our developers. Can you just confirm that I am understanding the process correctly? Thanks so much for your assistance.

April 27, 2019 at 7:28 am #3694765

laura-dY

What I really wanted was for there to be one place to add the experts and order them for all languages, but I am realizing now that's probably an unrealistic expectation. I know that we will have the same experts in the same order for all languages, but the system can't know that and that only works if we do.

So, more realistically, we need to have the relationship field for each language and I'll need to add the experts and order them for each language. So, in that case, yes, the experts should only show up in settings for their respective languages.

If there was a way to order all languages, when you order one, that would be great, but I understand that's probably not possible.

Thanks for your help!

April 29, 2019 at 9:09 pm #3706647

Lauren
Supporter

Languages: English (English )

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

Thanks so much for clarifying. I believe the issue is happening due to some changes when we released ACF Multilingual version 1.2. With this release, it changed the way that options fields are translated. The new way to translate the options strings is by using String Translation.However, as of right now, complex fields (such as relationship fields) are not showing in String Translation and thus cannot be translated. Our developers are currently working on a resolution that will be included in a future update.

In the meantime, if you downgrade to an earlier version os ACF Multilingual, we could check to see if it works correctly with that version. I will test this on the staging site that I have set up, but I wanted to let you know what I had found so far.

I will let you know the results once I have been able to test this. Thanks for your continued patience.

April 30, 2019 at 5:18 pm #3713863

Lauren
Supporter

Languages: English (English )

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

I can confirm with ACF Multilingual version 1.1, the correct experts show up in the respective languages. You still need to select which Experts to add to the list and adjust the order, but you no longer see the German Experts on the English settings page and vice versa.

I do not have an estimated time of when the options fields changes will be added to a future release, so for now I suggest this workaround.

May 1, 2019 at 9:40 am #3717281

laura-dY

Ok, thanks for the update. I downgraded to ACF Multilingual version 1.1 and the experts relationship field does seem to pulling in the proper posts in the appropriate language in the admin. However, now I am not able to get the English posts to show up on the front end at all.

I made some changes since I sent you the site so it's probably something I did, but I am unable to find it. Since this site is still in development and I had created a lot of custom fields that changed and was working with a lot of unnecessary meta values in the database that was getting confusing, so I created a new installation and imported only some basic content and started again. I also refactored the plugin that create the expert post type and the archive page but the relevant code in that plugin are basically the same.

The code I am using to adjust the WP Query to pull in posts from this relationship field on the archive page is:

	public function modify_expert_archive_query( $query ) {

		if ( $query->is_main_query() && ! is_admin() && is_post_type_archive( $this->post_type ) ) {

			$experts = get_option( 'options_experts_order' );

			if ( empty( $_GET['dept'] ) ) {

				$query->set( 'post__in', $experts );
				$query->set( 'orderby', 'post__in' );
				$query->set( 'posts_per_page', '-1' );

			} else {

				if ( isset( $_GET['dept'] ) ) {
					$departments = $_GET['dept']; //get sort value
				}

				$taxquery = array(
					array(
						'taxonomy' => 'department',
						'field'    => 'slug',
						'terms'    => $departments
					)
				);

				$query->set( 'tax_query', $taxquery );
				$query->set( 'post__in', $experts );
				$query->set( 'orderby', 'post__in' );
				$query->set( 'posts_per_page', '-1' );

			}
		}
	}

This is inside a class in which $post_type is defined.

This works fine for the German pages, but I can't see why nothing shows up in English.

Can you have another look? I can duplicate the new installation and send.

Thank you.

May 1, 2019 at 3:10 pm #3718717

Lauren
Supporter

Languages: English (English )

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

I think the best thing to do at this point is to try and reproduce the issue on a clean install, because there is a lot of custom programming happening on your site. If we can reproduce on a clean install using less custom programming, then I can escalate this issue to our compatibility developers.

I have set up a clean install here and downloaded ACF Pro and all WPML plugins. I also installed Toolset. Please create the CPT using Toolset and then add the options settings via ACF as you did in your live site.

We can then use Toolset Views to display the CPT on the frontend, and check to see if it displays in both languages. Here is the access to the test site:

Login: hidden link
Username: demo
Password: 3kG03Nd3lvYU

Please let me know once you have created the custom post type and fields. I will be happy to set up the Toolset View once that part is completed.

May 2, 2019 at 10:52 am #3723913

laura-dY

Hi Lauren,

Thanks for setting that up, but actually, I've narrowed this down to the pre_get_posts function I posted above so I think I've already isolated the issue which wouldn't be a part of the new installation so I don't think that will help.

The issue is that the line

$experts = get_option( 'options_experts_order' );

only pulls in the German

experts_order

relationship field.

If I change it to

options_en_experts_order

I get the English version.

So, I just need a little help figuring out how this works and if it will change once you update the new version of the ACF Multilingual plugin. You mentioned specifically that the new version changes the way options fields are translated, so I want to make sure whatever function I use will work going forward.

For example, I tried using:

$experts = get_option( 'options_' . ICL_LANGUAGE_CODE . '_experts_order' );

which works well for English and I am guessing will work for future languages, but the default language (German) doesn't work because I need

options_experts_order

not

options_de_experts_order

Is there a way to check for the default language first and then use the above code only for additional languages? And will this change with the next version?

Thanks!