[Plugin: Polylang] pll_copy_post_metas and custom post types
-
hi,
I’m trying to copy automatically my post metas to new translations.
I have a custom post type with custom fields created using the Type plugin:
http://ww.wp.xz.cn/extend/plugins/types/This is the code I added to functions.php :
add_filter(‘pll_copy_post_metas’, ‘copy_post_metas’);
function copy_post_metas($metas) {
return array_merge($metas, array(‘wpcf-squadra_playlist’));
}In this example I tried to copy my custom field wpcf-squadra_playlist.
Why it is not working?rob
-
is it just possible to copy the content of custom fields while translating custom post types?
or pll_copy_post_metas() works only with posts and pages?rob
It should work with any custom post type provided that you registered it with ‘custom-fields’ support. I just remade a test and it works. However I did not test the compatibility with the mentioned plugin.
You are right.
I enabled custom-fields support for custom post types and now I can see the content of the custom fields imported in the translations.At this point the issue is only related to the Type plugin I mentioned.
Even if the custom-field value is populated (I can see it in the original custom fields box), the value is not imported in the custom fields interface showed by Type.I will investigate.
Thank you Chouby!rob
Dear Chouby, Dear Quelvin,
First of all, polylang is really an awesome plugin.
I think I have a similar problem to Quelvin’s and have found no solution so far. If you could help me that would be great. I will try to give you as much informations as possible.
I am using the same plugin called types or wp-types (http://wp-types.com/ or http://ww.wp.xz.cn/plugins/types/) and created a custom post type with custom fields on it and the synchronisation doesn’t work well. You can find the website here:
http://server42.cyon.ch/~elsaswit/elsa_switzerland/fkar4daww2/suisse/1. What I did:
1.1 I created a custom post type called “events” (see PDF)
1.2 I created a custom field group called “Events informations” with (see PDF)
– various custom fields in it, most of them being required
– the custom post type “events” selected so theses custom fields appear on it
1.3 I added to my child theme functions.php the followingadd_filter('pll_copy_post_metas', 'copy_post_metas'); function copy_post_metas($metas) { return array_merge($metas, array('wpcf-starting_date_time', 'wpcf-ending_date_time', 'wpcf-status', 'wpcf-cost_type', 'wpcf-member_fee', 'wpcf-non_member_fee', 'wpcf-currency', 'wpcf-registration', 'wpcf-registration_email', 'wpcf-registration_link', 'wpcf-contact', 'wpcf-website_address', 'wpcf-website_yes_no', 'wpcf-website_address')); }1.4 I created a new post of the custom post type “events” called event5-en in english, filling the various custom fields of in “Events informations” (see images in PNG)
1.5 I added a german translation of the post, calling it “event5-de”. (see image in PNG)2. What happens:
2.1 For the english post, the “Event informations” custom fields appear both
– under their section, and
– as individual user added custom fields just below
2.1 For the post in german
– the “Events informations” are empty and have to be filled again
– the “Events informations” custom fields of the english post are copied as individual user added custom fields just below3. Note: I tried everything from deactivating/activating sync options in settings, adding or removing the pll_copy_post_metas filter in functions.php and I really don’t understand what is happening and what to do. (current status of my “Settings” tab of polylang in PDF here).
Thanks a lot
Ogma
What an old topic you found here! Things have changed quite a lot during the past year. Now it is no more useful to code to get your custom fields copied since Polylang does this by default for all public custom fields. There are even synchronized between translations if you keep the relevant option checked in Polylang settings.
Well… That said, there is an incompatibility between Types and Polylang because Types loads the custom fields values much before Polylang does for the standard WordPress custom fields. As you observed, these one correctly filled.
So I went diving into Types code and found that there are using an undocumented function of WPML to get the custom fields correctly copied when Types is used together with WPML.
I made an attempt to emulate this WPML functionnality. You can try with the new development version (1.1.1.2)
http://downloads.wp.xz.cn/plugin/polylang.zipLet me know if it’s OK for you.
NB: It seems that Types “locks” the custom fields values copied by WPML. It is what I noticed during my tests when I created a new translation (can’t change this). However, the values are unlocked once the translated post is saved and reopened.
I believe that WPML would keep them locked but Polylang doesn’t. The reason for this is that, as far as I know from my old tests with the latest freely downloadable version of WPML, you are obliged to have all posts in the default language. This is a limitation that Polylang doesn’t have.
Chouby,
It works ! Awesome, thank you ! I have two last small questions and some additionnal feedback informations:
1. Questions:
1.1 Is it normal and ok that the “Events informations” custom fields appears also a second time in the list of user-added custom fields just below ? It happens for all languages, even the first one.
1.2 Do I have to delete the development version you gave me and wait for you to implement it in a official release or can I keep it as a normal version ? I am afraid it is going to interfere somehow with the update mecanism or something else.
3. feedback informations: I tested some possibilities when custom fields are modified to see if the modification would be synchronised. I tried to modify a field in the english version but it didn’t take in the german and french version, the data was still the old one. But I don’t need to have that advanced functionnalities. I mean, your plugin is free, so great already, even better with the modification you added in your last post. I sent you that information just in case you would need it in the future.
By the way, I cannot believe I could be of any help right now with my ultra-low level in PHP programming. But do you need some help with basic stuffs (translation english-french or things like that) ? If so, tell me. I don’t have much time but I’d be glad to do what I can.
Thanks a lot !
Ogma
1.1 -> I suppose it is normal as this happens even if Polylang is de-activated and Types creates native WordPress custom fields. You can always hide the custom fields metabox.
1.2 -> You can keep the version as is. It will not interfere with the automatic update process.
3. -> I made basic some tests and did not run into any issues with custom fields synchronization together with Types. Did you check the relevant option in Polylang settings?
Thank you for your help proposal. What I most need is testing and bug reports when I make development versions available. You can subscribe to the Polylang blog to know when I release development versions.
Dear Chouby,
Thanks again for your answers. I will try to check/uncheck options in the settings, but it is already perfect for me like that.
I will look at the polylang blog.
Keep up the great job !
Best regards,
Ken
The topic ‘[Plugin: Polylang] pll_copy_post_metas and custom post types’ is closed to new replies.