Title: [Plugin: Polylang] filter meta
Last modified: August 20, 2016

---

# [Plugin: Polylang] filter meta

 *  [zbrass](https://wordpress.org/support/users/zbrass/)
 * (@zbrass)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/plugin-polylang-filter-meta/)
 * Hi
 * How do i use this filter?
 *     ```
       add_filter('pll_copy_post_metas', 'copy_post_metas'); function copy_post_metas($metas) {
            return $metas+array('my_post_meta');
       }
       ```
   
 * I have a custom_value persons the content i want to export to the translated 
   post. how?
 * best regards,
 * Arthur
 * [http://wordpress.org/extend/plugins/polylang/](http://wordpress.org/extend/plugins/polylang/)

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/plugin-polylang-filter-meta/#post-2615373)
 * If you create a custom filed with *name* ‘persons’, then Polylang will copy the
   custom field value if you add this code:
 *     ```
       add_filter('pll_copy_post_metas', 'copy_post_metas');
       function copy_post_metas($metas) {
            return $metas+array('persons');
       }
       ```
   
 * You can add this code to your theme functions.php or create your own plugin with
   these lines
 *     ```
       <?php
       /*
       Plugin Name: My Plugin
       */
       ```
   
 * and then the code mentionned above.
 *  Thread Starter [zbrass](https://wordpress.org/support/users/zbrass/)
 * (@zbrass)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/plugin-polylang-filter-meta/#post-2615568)
 * Hi Chouby thanks for the answer.
 * But for me return `$metas+array('persons');` does not work
    I use return `$metas
   =array('persons');` so instead of a `+` a `=` and that works. Is this a bug? 
   Or is this safe for the future?
 * regards,
 *  [Andis](https://wordpress.org/support/users/andydegroo/)
 * (@andydegroo)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/plugin-polylang-filter-meta/#post-2615617)
 * That would disable copying of other meta fields when translating. You would loose
   page template and featured image which are stored as meta values.
 * More reliable would be to use `array_merge` rather than array concatenation which
   works differently with numeric keys.
 * Try this:
 *     ```
       add_filter('pll_copy_post_metas', 'copy_post_metas');
       function copy_post_metas($metas) {
            return array_merge($metas, array('persons', 'other_custom_meta'));
       }
       ```
   
 * [@chouby](https://wordpress.org/support/users/chouby/) This might be a bug or
   a feature, depending on what you want to achieve – read [about array operators in PHP manual](http://php.net/language.operators.array).
   
   I’d also suggest to use `array_unique($metas)` in `Polylang_Admin_Filters::save_post()`
   so you don’t have to loop through duplicates. That would be a performance improvement
   if there are many meta fields to copy or sync. Maybe it would be even faster 
   to use `get_post_custom($post_id)` and then iterate over the returned array rather
   than calling `get_post_meta()` for every entry which may be slower.
 *  Thread Starter [zbrass](https://wordpress.org/support/users/zbrass/)
 * (@zbrass)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/plugin-polylang-filter-meta/#post-2615625)
 * Works on all 🙂
 * Great thanx Andy!
 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/plugin-polylang-filter-meta/#post-2615640)
 * Of course you are right ! I will modify the documentation, and will look for 
   your suggestion for the save_post function. Thanks a lot !
 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/plugin-polylang-filter-meta/#post-2615705)
 * [@andydegroo](https://wordpress.org/support/users/andydegroo/). In the new dev
   version (0.8.0.7), I tried to follow your advice. As a bonus, it is now possible
   to synchronize metas which have multiple values for the same meta key.
 *  Thread Starter [zbrass](https://wordpress.org/support/users/zbrass/)
 * (@zbrass)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-polylang-filter-meta/#post-2615813)
 * Hi Chouby and AndyDeGroo,
 * The pll_copy_post_metas works great but what do i do with meta data from pages?
   
   The filter does not see these metas.
 * Do you have a solution?
 * Thanks!!
 * Arthur
 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-polylang-filter-meta/#post-2615819)
 * There should be no differences between posts and pages. My tests work for both.
 *  Thread Starter [zbrass](https://wordpress.org/support/users/zbrass/)
 * (@zbrass)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-polylang-filter-meta/#post-2615820)
 * Thanks.
 * Strange i try to filter the metas produced by the plugin [Advanced Custom Fields](http://www.advancedcustomfields.com/)
   but that does not seem to work.
    Any idea?
 * Arthur
 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-polylang-filter-meta/#post-2615822)
 * I made a small test with advanced custom fields and it works perfect for me using
   this code snippet:
 *     ```
       add_filter('pll_copy_post_metas', 'copy_post_metas');
       function copy_post_metas($metas) {
       	return array_merge($metas, array('my field name'));
       }
       ```
   
 * Did you take care to use the field name and not the field label ?

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘[Plugin: Polylang] filter meta’ is closed to new replies.

 * ![](https://ps.w.org/polylang/assets/icon-256x256.png?rev=3433336)
 * [Polylang](https://wordpress.org/plugins/polylang/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/polylang/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/polylang/)
 * [Active Topics](https://wordpress.org/support/plugin/polylang/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/polylang/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/polylang/reviews/)

 * 10 replies
 * 3 participants
 * Last reply from: [Chouby](https://wordpress.org/support/users/chouby/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-polylang-filter-meta/#post-2615822)
 * Status: not resolved