• Resolved philbee

    (@philbee)


    I have a site with two custom Post types, created in Pods, but now switched over to hardcoded CPT and taxonomy creation and ACF Pro for the Custom fields.

    What I’m trying to do is to tell Polylang to copy some custom fields and to synchronize the other custom fields.

    For example:
    copy event_description, so that an events’ programme can be displayed in english as well as german.
    synchronize event_date, since that’s never going to be different in any language.

    I added this code to my custom plugin:

    add_filter('pll_copy_post_metas', 'copy_post_metas');
    function copy_post_metas($metas) {
          return array_splice($metas, array('event_description'));
    }
    add_filter('pll_copy_post_metas', 'merge_post_metas');
    function merge_post_metas($metas) {
          return array_merge($metas, array('event_date'));
    }

    but now Polylang simply creates translations with empty custom fields. Nothing is copied, nothing is synchronized.

    What am I doing wrong?
    Thanks for any insight!

    (BTW, the Polylang filter reference is a bit opaque, at least to non-programmers, IMHO. What’s the $sync argument, where does it appear if at all?)

    Permalinks: /sample-post/
    Static Front Page: yes
    Polylang settings: 2 languages, Synchronization: Custom fields ON

    https://www.ads-software.com/plugins/polylang/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter philbee

    (@philbee)

    Maybe I should add: I deleted WPML (sitepress-multilingual-cms) and all its other PlugIns, so it’s not any old wpml-config.xml that’s messing things up.
    Also, with no pll_copy_post_metas active, all custom fields are being synchronized, which is obviously better than having them empty in the translated CPT (event or member), but not ideal.

    Thread Starter philbee

    (@philbee)

    Looks like I found the solution:
    uncheck Sync Custom Fields in Polylang
    add only the Custom Fields one needs to be synched

    add_filter('pll_copy_post_metas', 'merge_post_metas');
    function merge_post_metas($metas,$sync) {
          return array_merge($metas, array('event_date','event_starting_time','member_first_name','member_last_name'));
    }

    Seems to work so far. Maybe this should be added to the Filter documentation, for clarity’s sake?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Polylang: selective pll_copy_post_metas?’ is closed to new replies.