Relation objects not loaded from translated pod
-
Quick sketch of the situation: I’ve made two pods: Product and Indication (=treatment). Each product has multiple Indications and vice versa. This works well in one language. When using other languages I’ll have to build the same relationships again between translated products and translated indication, even when playing with the WPML custom field translation options. As a workaround, in the template of a product, I will load the pod of the original language object, after getting the id through wpml_object_id filter. Then I get the pod of the product with that id (= same product in the original dutch/nl language. Then the plan is to get the indications there and in a loop load the translated indications through the same wpml filter. A little detour but should be simple enough.
Issue: I can get the object in the original nl language, I can get every field, except indication, that field stays empty… If I run the code in the original language then it works, in any other language it doesn’t
<?php //astra_content_loop();
echo "debug: my id" . get_the_ID();
$dutch_post_ID = apply_filters( 'wpml_object_id', get_the_ID(), 'product', true, 'nl' );
echo "debug: original language id " . $dutch_post_ID;
$pod = pods('product', get_the_ID());
$pod_nl = pods('product', $dutch_post_ID); //get the original object in dutch in order to get linked indication and images as translation goes wrong
$intro = $pod->field('introduction');
$intro_og = $pod_nl->field('introduction');
//we get the product image from the original nl object because the product images doesn't get copied like we ask WPML
$product_image = $pod_nl->field('product-image');
//we get the linked indications from the original NL object so we don't have to manually link all translated objects with their correspondig translated indications again
$indications_og = $pod->field('indications');
$indications = $pod_nl->field('indications');$indications_og will get populated with the linked indications in the current language, but $indications will stay empy…
The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.