Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:

Pods plugin issue. Custom post-type relationships and files are showing the translation.

Solution:

The Pods plugin is not officially compatible with WPML. We have a few reported compatibilities issues. In this specific case, the user shared the way he was able to solve this issue. Please read it here.

https://wpml.org/forums/topic/custom-post-type-relationships-and-files-not-translated/#post-8750157

0% of people find this useful.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 4 replies, has 2 voices.

Last updated by Itamar 3 years, 8 months ago.

Assisted by: Itamar.

Author Posts
May 10, 2021 at 7:16 pm #8732685

rafaelO-5

Tell us what you are trying to do?

I have a multilingual site with a custom post types: "book" in relationship with "book_author" (made with pods). Only the site web interface is multilingual and not the books or authors.

After a bit I've realized the only way to show the non translatable books and book authors was to "duplicate" the content (!!), creating this kind of link between the two objects (primary and secondary language).

I've made it work to translate the taxonomies, that are showing up properly in both languages.

The issue is with relationships, images and other files; they are not copied over to the secondary language nor a kind of "link" is created (which would be ideal).

So first I've "duplicated" all the book_author and then the books, which they are related to one or more book_author. I've verified that all the "Custom Fields Translation" fields of the book and book_authors are set to translate.

I've followed all the thread of

https://wpml.org/forums/topic/wpml-doesn-show-translated-relationship-custom-fields/

where it's recommended to use the function https://wpml.org/wpml-hook/wpml_object_id/ to retrieve the original language content (and then retrieve the field) or remake all the associations (!!).

My question are:
1 - is there something new in the way I could solve this?
2 - why relationships images and files are not duplicated as well like the other fields? perhaps with a kind of link instead of duplicating the content? this behavior seems a bug to me.
3 - if I have to use the wpml_object_id filter, wouldn't be best at this point to fetch all the fields with this filter instead of duplicate them?

I can give you access to the site

May 11, 2021 at 8:21 pm #8743079

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi,

1 - is there something new in the way I could solve this?

I'm sorry there is anything new regarding this issue I can share with you that will help you solve this issue.

2 - why relationships images and files are not duplicated as well as the other fields? perhaps with a kind of link instead of duplicating the content? this behavior seems a bug to me.

You are experiencing a known issue that we have. Please read the following link to the errata page and implement the workaround.

https://wpml.org/errata/pods-image-custom-field-added-by-pods-is-not-copied-over-the-translation/

Also, you should be aware of the following known issue that we have with Pods.

https://wpml.org/errata/pods-custom-post-type-has-issues-saving-translation/

3 - if I have to use the wpml_object_id filter, wouldn't be best at this point to fetch all the fields with this filter instead of duplicate them?

I'm not exactly sure what you are asking. In any case, we also have hoks for filtering custom fields. Please check our hooks reference page here.

https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

Regards,
Itamar.

May 12, 2021 at 2:46 pm #8750157

rafaelO-5

Overall I think it's a pity that you need to duplicate the content to make it available on the other language even though you don't need a translation.

In the "Custom Fields Translation" you can find "Don't translate", "Copy", "Copy once" and "Translate".. there should be a "Fallback to original" that fetches the original language if the translation is not found at a field level.

On the "Post Types Translation" i've set my Pods to "Translatable - use translation if available or fallback to default language", and to test it I've delete one translation, so I would expect it would fetch the english version but WP give a "Nothing here" (404 not found). And how this would work for associated translated taxonomies?! anyways I haven't understood the conditions for this to work; so i duplicated the content.

In case anybody else is trying to do the same thing I've used the wpml_object_id filter to fetch the english version on my template in case the secondary language is active: this is NECESSARY because associated images or other files (ebooks, pdfs) or pods relationship are NOT working at the moment with WPML. Ideally you wouldn't want to duplicate for example 1000 pdfs / 1000 ebooks or the same image that is used for both the translation and primary language. You would want to keep just a link/reference/pointer.

Here's a few code snipped to the fetch the original language. This is for fetching a relationship:

        $el = $args['el'];
 
        if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
           $language = ICL_LANGUAGE_CODE;
        }
        $author = $el->field( 'book_author' );
        if ($language == 'bo') {
            $el_en_id = apply_filters( 'wpml_object_id', $el->field('ID'), 'book', TRUE, 'en' );
            /* Alternative way
            $params = array( 'where' => 't.ID = '.$el_en_id, 'limit' => -1 );
            $el_en = pods('book', $params);
            echo "Author: ".$el_en->field(book_author);
            */
            $book = pods( 'book', $el_en_id);
            $author = $book->field( 'book_author' );
        }
        if (is_array($author) || is_object($author))
        {
            foreach($author as $item) {
                $id = $item[ 'ID' ];
                if ($language == 'bo') {
                    /* Alternative way
                    $book_author_pod = pods( 'book_author', $id);
                    echo $book_author_pod->field( 'author_name_tib' );
                    */
                    echo get_post_meta( $id, 'author_name_tib', true );
                } else {
                    echo $item['post_title']." ";
                }
            }
        }

Fetching an image:

if ($language == 'bo') {
        $en_id = apply_filters( 'wpml_object_id', get_the_id(), 'book', TRUE, 'en' );
        $book = pods( 'book', $en_id);
        $image_array = $book->field('book_cover.guid');
    } else {
        $book = pods( 'book', get_the_id() );
        $image_array = get_post_meta( get_the_ID(), 'book_cover', false );
    }

Another similar test to fetch other files:

if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
			$language = ICL_LANGUAGE_CODE;
		}
		$book = pods( 'book', get_the_id() );
		if ($language == 'bo') {
			$en_id = apply_filters( 'wpml_object_id', $book->field('ID'), 'book', TRUE, 'en' );
			$book_en = pods( 'book', $en_id);
		}	
		$file_ebook = ($language == 'bo')? $book_en->field( 'ebook_file.guid' ) : $book->field( 'ebook_file.guid' );
		$file_pdf = ($language == 'bo')? $book_en->field( 'pdf_file.guid' ) : $book->field( 'pdf_file.guid' );

It would be nice if you guys had a one page documentation for Pods custom types with examples of different scenarios.

Thank you!

May 12, 2021 at 2:52 pm #8750425

rafaelO-5

I know you guys are supporting Toolset but you should consider adding Pods here: https://wpml.org/plugin-functionality/custom-post-types-taxonomy/

Even on Toolset they are comparing it with Pods, ACF etc: https://toolset.com/home/comparing-toolset-to-free-and-paid-alternatives/

A more complete comparison is made by pods[dot]io here: hidden link

Thank you for your work!

May 12, 2021 at 4:03 pm #8750807

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi, and thanks a lot for adding your finding and inputs on this issue. I'm sure it would help other WPML and Pods users. I can see in our internal documentation that there is an intention from our side to make Pods officially compatible with WPML because many of our users also use Pods. Nevertheless, this process might take time. It depends on many factors. Because Pods is a community project (vs. a commercial plugin), this might make the compatibility process even longer. When it is compatible, you will be able to find Pods on our list here. https://wpml.org/plugin/. And hopefully, our documentation team would also add a guide on using WPML and Pods together.

Please let me know if you have any further questions regarding this issue.

Cheers,
Itamar.