Accueil › Toolset Professional Support › [Résolu] translation problem when sorting by category
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | - | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 |
- | - | - | - | - | - | - |
Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)
Marqué : Types plugin, Views plugin
Ce sujet contient 29 réponses, a 3 voix.
Dernière mise à jour par olivierF Il y a 6 années et 6 mois.
Assisté par: Beda.
All Toolset Plugins, WPML, Theme and other related Plugins are out of date.
Moreover you seem to use 3 versions of Types:
2.2.21
2.2.23
Let's start here:
- Update the system,
check the issue again
- Disable non Toolset plugins if it persists,
check the issue again
- Disable the Theme if the issue persist,
and check again
I am quite sure the issue will only be the wrong URL language parameter but the content should by then be correct.
Please let me know.
I could not see the page where you use the View.
This here, where do you edit it?
lien caché
That can later help to debug it further in case the issue persists.
It seems to me that is an archive, hence not a View but a WordPress Archive (of which you have none) should be used here.
HI,
I updated all plugins, i disabled all unnecessary plugins, I deactivated and reactivated the theme but it does not change anything, there is always the same problem.
The page is 'Artistes' with the custom template 'label_artists_vue' (in the jauneorange theme folder). The view is integrated in the custom template.
Hi, I changed my admin language to English, I hope that is fine (not the site's language of course, just my users admin language)
Analyzing that page, I see that lien caché presents JS errors, without even running a search.
If you first run a search, it won't work, you need to click again.
Same on the translated page.
I read you use a Custom Template to output that View and wanted to test right there on a new page, without custom template, but I cannot even see what I put in the postboy, see here:
lien caché
Please can you test this without the Theme?
I do not know how you call the View, but it does not seem to be a native way.
Are you using PHP for this?
Hi Breda, hi Nigel,
The problem comes from the plugin snippets that I installed with the assistance of Nigel (see a previous ticket https://toolset.com/fr/forums/topic/sort-by-date-post-relationship/page/2/ ), when I disable it, it works but I have another problem that occurs, I have either a problem or another.
What can I do to solve these two problems?
Thank you for your collaboration.
Olivier
That code proposed there seems to address a post id while a post is saved, hence, just the current post, not its translation, and you would need to at least resave your posts to apply that code.
It's the only I can think of if you have any issue with that code and later with the multilingual search.
Or are you saying that if you remove that code, then the View already works as expected, which would mean the code provided there somehow affects the query of the view without even submitting new / editing posts?
This is somehow not possible.
I am not sure what else was done on the site with Custom Code, but we cannot debug custom code.
We can however help to see where the issue may come from.
As far I see, the code provided there, implies posts to be saved.
If that does not happen, removing that code should not have any influence over your site, neither if you have it enabled.
Only if you save a post it triggers.
Hence if the View's results are correct after you remove that code, and save new posts, then the issue is that the code does not address translations, most likely.
Otherwise, I am not sure where the issue could be, as the code should "work" only if you save a post, not when you query them in a View.
Can you explain to me how that code relates to the lost URL parameter and wrong results?
If it is due to the save action of posts, then it is required to update that code to a multilingual process.
That we would need to look at in depth, but I will first wait for your information about it so I can make myself a picture of it.
I confirm that when I disable the plugin snippets, the view and translation work properly, but as soon as I activate the plugin, it does not work anymore.
here's what happens when the plugin is enabled or disabled. (capture.jpg)
When disabled the view on the page lien caché does not work anymore
What plugin?
I thought we spoke of code that Nigel applied for you on the thread you linked?
I must misunderstand something.
Was that code added to a plugin?
Is it a plugin I can download somewhere?
Is it included here?
https://toolset.com/fr/forums/topic/translation-problem-when-sorting-by-category/#post-906077
This is the "snippets code" plugin recommended by Nigel lien caché
Here is the discussion with Nigel https://toolset.com/en/forums/topic/sort-by-date-post-relationship/.
the code is added through the plugin in the admin.
OMG, OK, I apologize, I did understand that the code Nigel provided, was the cause.
Instead it's a third party plugin.
So we have a compatibility problem with the plugin and Toolset.
Can you try to put those codes in the functions.php, where they belong, and remove the plugin (deactivate) to see if that resolves the issue?
Then we can still contact that developer to find a solution to the issue
I deleted the plugin, I copied the code in my file functions.php but the problem on the page lien caché still exists. I think you have to play the function a first time but I do not know how.
OK.
I am confused because before, it seems the plugin was culprit, but now it seems that code is culprit and then the issue is as I outlined, it only updates the current posts, not it's translations, that is visible in the code.
However custom code issues we cannot debug here, I can ask Nigel to look into his code about multilingual purpose, but I need to know what causes this issue, especially since it's not replicable on the very duplicate after the steps I outlined in past.
Logically, since I removed non-toolset Software in my tests, that plugin did not load it's code, but as I said, that code only hooks into the save_post() hence it cannot affect the search, unless we save new posts each time and update something that then messes up the search.
I need to know wether the Plugin you use is the cause, or the Code Nigel provided you.
In the first case, we will open a compatibility process.
In the second case it's custom code, and our possibilities are limited.
Basically, we would need to rethink what was provided to you there.
I think I will work together with Nigel on this as he was the one helping you with the code.
This means, I will speak to him on Monday and handle this ticket with his insight of the other ticket.
Then we will reply you here with news about what to do and wether or not we can help with the custom code, and if yes, we will provide a example solution.
Thank you for your patience meanwhile.
I bespoke this with Nigel and this is the information I got.
Note that we cannot assist this issue, but please let me elaborate.
1. The problem was that the you had a Types Legacy Many To Many relationship where "participant" is the intermediate (child) post of 'concert' and 'artist'.
2. Concert has a "concert date" field.
3. A View is added to the artist template which displays related concerts (the View queries participant posts and outputs fields of the parent concert).
4. You wanted this View to output concerts ordered by "concert date".
This is not possible because concert date is a field of concerts, not of participants, which is what is being queried.
There are however plans to add "doing things by related fields" features, which means, we plan to allow Custom Search, Query and Sorting by Fields that are in posts related to the currently queried one (as example, by parent post)
So, strictly speaking, we cannot help with that yet.
The features are planned and any custom code applied is to be used under own responsibility.
Nigel's suggestion was that you duplicate the concert date field from concerts to participants whenever saving a participant intermediate post.
But that didn't affect his existing posts, so he provided a one-time script to run through the existing participant posts and duplicate the concert-date field.
That last code should NEVER be run again.
The first code shall be kept in your functions.php
Now, that code Nigel provided does NOT respect translations, duplications to translated content, etc.
That is not part of what we can support, it requires custom code again.
The custom code that Nigel Provided is working for Language (current posts language).
It will however never update it's translations.
For that, you would need to craft your own code that updates the Translations as well, according your choices and code.
The WPML API is here:
https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/#inserting-content
To solve the issue you either need to remove the code, wait for the feature to be implemented, or, apply custom code that adds the translated (updates) content as well
We can however not help with this, but the Contractors could, in case you need this feature bi-linbgual
https://toolset.com/contractors/
Hi Beda,
I do not understand why Nigel's code does not work anymore, it worked fine, I do not need translation for these fields, so wpml has nothing to do.
Is it having to disable snippets? Even when I encode a new date it does not work anymore, yet it is displayed correctly for one of the dates (see capture) why ?
For when the update Toolset is planned? it seemed to me to be something basic and I have to deliver the site soon, I'm a little off guard.
Thanks in advance
Olivier
1. I do not need translation for these fields, so wpml has nothing to do.
Well, but we are analyzing a Problem where a view returns wrong results of a wrong language, apart of the problem that the URL parameter gets lost.
That code, both snippets, work on the Current post that you edit or create.
So, if that post later gets translated and should or should not display on the relative View results in each language, then the data which the Custom Code adds, is not added to your translated posts and searching by the same data, will result in wrong posts shown.
You mentioned removing that code resolves the issue.
That code applies only to the currently edited post and hence does not sync the translations - the data added, the actions it does, are not applied to your translations and hence that same View will not work the same in a translated results list.
2. Is it having to disable snippets? Even when I encode a new date it does not work anymore, yet it is displayed correctly for one of the dates (see capture) why ?
You already confirmed the issue is solved if that code is removed.
But we deviate, I read now that the code is not working anymore even in the current post/language?
This is a totally new issue.
Does removing that code snippet solve the issue?
It would confirm why when I try to replicate this problem on your copy of the site, I cannot see the issue:
https://toolset.com/forums/topic/translation-problem-when-sorting-by-category/#post-907758
3. The update including that feature has no ETA yet.
Now, let's move on.
I want to solve this problem for you and re-downloaded the package and deployed it again to find out, if that code has an influence over the issue and if I can spot the source (any that is not yet known) of the issues.
I replaced all Toolset and WPML plugins with the current ones and checked if the JauneOrange Theme you use still had the Code active which needs to run just once (and hence, should NOT be present in the theme anymore):
function tssupp_duplicate_parent_fields_once (){ $child_slug = 'participant'; $parent_slug = 'concert'; $parent_field_slug = 'concert-date'; // Get all of the child posts $args = array( 'post_type' => $child_slug, 'numberposts' => -1, 'post_status' => 'publish' ); $child_posts = get_posts( $args ); if ( !empty( $child_posts ) ) { foreach ($child_posts as $child_post) { // get the ID of the parent post $parent_id = get_post_meta( $post_id, '_wpcf_belongs_' . $parent_slug . '_id', true ); if ( !empty( $parent_id ) ) { // get the parent field $parent_field_value = get_post_meta( $parent_id, 'wpcf-' . $parent_field_slug, true ); // duplicate the parent field on the child post update_post_meta( $post_id, 'wpcf-' . $parent_field_slug, $parent_field_value ); } } } }
But, the theme (correctly 🙂 ) does NOT feature that code, hence, that code cannot be the cause of this issue in the sense of "If disable it, the issue is resolved".
I see that the other Snippet Nigel provided is still in the Theme, and according Nigels Instructions this is required.
That is OK.
I commented the code snippet below, so it's clear what it does:
function tssupp_duplicate_parent_field( $post_id, $post, $update ){ //$post_id is the current edited/created post ID, $post the current post object. NOT it's translation. ONLY the current edited or created post no matter in what language. $child_slug = 'participant'; //We determine the slug of a post type, child role $parent_slug = 'concert'; //We determine the slug of a post type, parent role $parent_field_slug = 'concert-date'; //The slug of the field that is stored on a parent post // is it a child post being updated? if ( $child_slug == $post->post_type ) {//Check if the current post saved/edited is of type "participant" // If yes, get the ID of the parent post $parent_id = get_post_meta( $post_id, '_wpcf_belongs_' . $parent_slug . '_id', true ); if ( !empty( $parent_id ) ) { //If a parent exists // get the parent field $parent_field_value = get_post_meta( $parent_id, 'wpcf-' . $parent_field_slug, true );//get the field 'concert-date'; // duplicate the parent field on the child post update_post_meta( $post_id, 'wpcf-' . $parent_field_slug, $parent_field_value ); } } }
Now, as we see, that code does NOT touch the post types involved in the View which you reported as broken in your initial post, which is Label_artists_vue, and queries "Artistes" post type.
Artistes post types are not involved in that code at all, so I do not think this has an influence over the behavior, and is not related to this ticket if it (that custom code) does not work anymore, as the issue would be another.
This new problem is not the issue reported here, and not related.
Now, Artistes Post Type, which is the post type queried by that problematic view, is translated and exists in the secondary (English) language of your site with few posts (4) and several more in the default language (french).
This is what I see on the duplicate I have.
The View is inserted as well in a page, which is translated to both languages.
So we would expect this View to return only English Results in the English page, and only French in the French page, and no mixup when you submit a search.
Since however the View looses the URL param with this specific constellation, the results are wrong.
What are the possible solutions until we fix the problem with the URL attribute?
1. Use a Submit button (not an AJAX updated View). That works fine
2. Or, in WPML Settings, change from ?lang parameter to "language in directories" URL settings, so the languages are shown as directories.
This works just fine.
Once the issue with the missing URL parameter is solved you can then turn back to ?lang parameter for example.
I'm going to use a search button, it works fine, the AJAX filter does not seem to work with WPML in my case. I am going to edit the old post to solve the other problem.
Thank you for you precious help.
Olivier