Reply To: Widget calendar and form not loading correct resource in WPML

Hi,

it works on the default language version, but it does not work in other language versions, for example:

http://bit.ly/O77Dm2 (please login with the information I sent you, the site is still in maintenance mode).

If you take a look at the right sidebar, in the select field for a resource, you`ll notice that the wrong resource is selected, and according to that, the calendar is not pulling the currently shown resource.

What`s even worse, is that if you click the “Jetzt buchen” button, the booking form on the next page does not load the appropriate, but the default resource. So that`s really an issue that I have to solve.

Oh, and I use Chrome, latest update.

NOTE: Okay, so I dug a little deeper, if you take a look at the source code for the select field, and check out the values for the select options, you`ll see that the form is not returning the correct post IDs for this site language version, all the IDs are from the english version, while browsing the post in german. So, as I see it, the problem is that obviously the query that is populating these fields is not aware of the language version of the current post. My guess is the problem lays in either the function easyreservations_resource_options or function easyreservations_get_rooms, even though I think the second one should be ok because it obviously works well on other places on the site.

ANOTHER NOTE: By adding icl_object_id($room->ID, 'easy-rooms') , or wrapping the $room->ID into WPML`s icl_object_id function in the entire function easyreservations_resource_options, I managed to get the select field to display the correct language IDs, but I still cannot get the form to automatically select the current post, so that the calendar and booking uses the current resource.

ADDITION TO THE SECOND NOTE: I don`t think that hacking the function easyreservations_resource_options will work in the end, because the function easyreservations_get_rooms is the one that is loading the incorrect resources, so obviously something has to be done before the easyreservations_resource_options even gets the data.

And besides that, I don`t need to show all the resources here, I just want the calendar to reflect the data for the current resource, I will ultimately hide the select field because I don`t need visitors to be able to choose anything here, so how can I just get the current resource to be reflected in the calendar widget and select field for the appropriate language version?

THIRD NOTE: Okay, so the problem is solved in regards to loading the correct resources depending on the shown language version. Here`s how:

On line 286 (might be different since I altered the code) in both.php, I replaced original lines with:


foreach($rooms as $key => $room){
$resources[icl_object_id($room->ID, 'easy-rooms')] = $room;
if($check){
$get_role = get_post_meta($room->ID, 'easy-resource-permission', true);
if(!empty($get_role) && ((!$user && !current_user_can($get_role)) || ($user && !user_can($user, $get_role)))){
unset($resources[icl_object_id($room->ID, 'easy-rooms')]);
}
}
}

So it was the function easyreservations_get_rooms that was causing the problems.