Custom Fields
Re-Envisioned
Support MB Custom Table Polylang and Custom Table Data

  • Creator
    Topic
  • #20789
    Resolved SL
    Participant

    Hello! I discovered this nifty plugin a few days ago and I couldn’t resist trying it out in full. So far, it’s pretty great. I am migrating from ACF for a little pet project of mine, but I’ve run into a bit of an issue.

    My pet project is essentially a “wiki” using wordpress. I have a custom post types (not Meta Box’s custom post type) for things such as Character, Universe, Meta, Children, etc etc. I’ll be using the Character post type as an example but this applies to all custom posts.

    I am using the Custom Table plugin to save the meta data such as their name, age, birthday, and other details to a table named wp_postmeta_custom. It’s working great and the data is going where I expect.

    In the old very complicated ACF set up, if I wanted a field to be the same across all languages, I created only 1 field for all languages (eg, age or birthday). If they needed to be translate/different (eg, character descriptions), I created new fields for every single language (eg, character-description-en, character-description-es).

    For this reason, I had Polylang’s (free version) field synchronization turned on.

    With Meta Box (and another year or two of experience), I am trying to use a more streamlined approach with a reduced need for so many fields. There are some fields I want to synchronize like before, and the others I would just like to copy the data when a new translation is added so users can translate more easily.

    Upon looking at Polylang’s documentation, they say the way to specify which custom fields should be synchronized is via wpml.config.xml file, which I have done.
    https://polylang.pro/doc/synchronize-metadatas-between-translations/

    <wpml-config>
        <custom-fields>
            <custom-field action="copy">character_birthday</custom-field>
            <custom-field action="copy">character_age_part1</custom-field>
            <custom-field action="copy">character_age_part2</custom-field>
            <custom-field action="copy">character_village</custom-field>
            <custom-field action="copy">character_affiliation</custom-field>
            <custom-field action="translate">character_alias</custom-field>
            <custom-field action="translate">character_appearance</custom-field>
            <custom-field action="translate">character_personality</custom-field>
            <custom-field action="translate">character_background</custom-field>
            <custom-field action="translate">group_fanon</custom-field>
            <custom-field action="translate">group_abilities</custom-field>
            <custom-field action="translate">character_trivia</custom-field>
            <custom-field action="translate">relationship_romantic_character</custom-field>
            <custom-field action="translate">relationship_family_character</custom-field>
            <custom-field action="translate">relationship_other_character</custom-field>
            <custom-field action="translate">character_gallery</custom-field>
            <custom-field action="translate">character_link</custom-field>
        </custom-fields>
        <custom-types>
            <custom-type translate="1">character</custom-type>
            <custom-type translate="1">children</custom-type>
            <custom-type translate="1">group</custom-type>
            <custom-type translate="1">neochild</custom-type>
            <custom-type translate="1">oc</custom-type>
            <custom-type translate="1">universe</custom-type>
            <custom-type translate="1">meta</custom-type>
        </custom-types>   
    </wpml-config>

    These are the field names going into my custom table. I won’t copy the entire code block, but here is an example for character_alias

    array (
                    'id' => $prefix . 'character_alias',
                    'type' => 'textarea',
                    'name' => esc_html__( 'Alias', 'text-domain' ),
                    'columns' => 12,
                    'label_description' => esc_html__( 'Add each alias on new line', 'text-domain' ),
                    'tab' => 'tab_character_details',
                ),

    I know it is working because the settings for Polylang no longer manages the custom post types I can translate (it is greyed out), this config file does.

    I expected when I add a new translation to an existing post, the data would be copied from the original post and I could edit it from there, but that is not the case.

    All the fields are blank. Am I missing a step? Does Meta Box Custom Tables work with Polylang? If not, I guess I’ll have to drop that feature and just use Meta Box without it and hope it works as expected.

    Thank you for any assistance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #20802
    Long Nguyen
    Moderator

    Hi,

    The Polylang plugin only takes the post meta in the table wp_postmeta to synchronize between translations so it is impossible to sync meta which is saved in the custom table.

    Your question needs support from Polylang developer and refers to this filter https://polylang.pro/doc/filter-reference/#pll_copy_post_metas.

    #20805
    SL
    Participant

    I see. I did come across that function, but I couldn’t figure out how to get the field data from the custom post. I found this on a help forum and tried to tie it in with rwmb_meta() and adding the table name argument.

    https://wordpress.stackexchange.com/questions/247520/polylang-not-translating-metabox-fields

    For now, I think I’ll go back to just using the wp_postmeta table and worry about this another time as I do need to get the updates live pretty soon.

    Thanks for confirming for me though! I thought I was going crazy.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.