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 11 replies, has 3 voices.

Last updated by babakF-3 4 months, 3 weeks ago.

Assigned support staff: Alejandro.

Author Posts
May 10, 2019 at 11:42 am #3783823

babakF-3

I am trying to:

I have a custom post type, "Program Item". This custom post type has a bunch of custom fields. One particular custom field, called "Long Term Project", is set to 'Copy' its values between languages. This is set for both 'English' and 'Dutch' languages. This custom field refers to another custom post type.

Though the value for this custom field is copied between posts in different languages, at least for one 'Long Term Project', the connected "Program Items" are not listed.

Link to a page where the issue can be seen:

English: hidden link
Dutch: hidden link

Both pages show a "Long Term Project". In English, the connected "Program Items" are listed. In Dutch they aren't.

On this page, I pick up the connected Program Items using a query with the following arguments:

$args = array(
'post_type' => 'program_item',
'orderby' => 'meta_value',
'meta_key' => 'start_datetime',
'nopaging' => true,
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'long_term_project', // name of custom field
'value' => '"' . get_queried_object_id() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
),
)
);

May 10, 2019 at 1:11 pm #3784725

Carlos Rojas
Supporter

Languages: English (English ) Spanish (Español )

Timezone: America/Montevideo (GMT-03:00)

Hello,
Thank you for contacting WPML support.

1.- Please describe the steps to reproduce the issue in the site.

2.- I would like to request temporary access (wp-admin and FTP) to your site to take better look at the issue. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

Our Debugging Procedures

I will be checking various settings in the backend to see if the issue can be resolved. Although I won't be making changes that affect the live site, it is still good practice to backup the site before providing us access. In the event that we do need to debug the site further, I will duplicate the site and work in a separate, local development environment to avoid affecting the live site.

Kind regards,
Carlos

May 14, 2019 at 12:31 pm #3806761

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Hello, my name is Alejandro,

Since Carlos is currently not available, I will replace him here in the forum.
I hope this is OK with you.

In inspected the code you mention and this is what i found ( i helped myself using your previous explanations + checking the site) but please correct me if i'm wrong, i just want to get the whole picture of this project so i can better help you out:

1) Program Items is actually called "Program Items Addition" and it's found here --> hidden link

2) This custom field is basically the structure for the long term projects (as seen here: hidden link )

3) I can only guess that the $args parameter is going to be used in a get_posts() function that will retrieve each post for each language, if that's the case then you might want to use the following parameter in the array of the $args variable:

suppress_filters => false

See if that makes any change.

I would also update your ACF Multilingual version to 1.3 just in case, since we fixed a few bugs with that version (although, they might not be related to your case, but it's better to be safe than sorry, plus that also helps us isolate the problem)

Let me know how it goes.

May 14, 2019 at 1:59 pm #3807811

babakF-3

Hi Alejandro,

Adding the 'suppress_filters" parameter did not make a difference. This parameter *is* now set for this set of arguments.

I updated ACF Multilingual.

"Program items" is the Custom Post Type. "Program Item Additions" is the set of custom fields added to this CPT.

I'm not sure I fully follow your point 2. The custom field that's relevant to this issue is called "Long Term Project" and is defined inside the set of custom fields called "Program Item Additions", which are tied to the Custom Post Type "Program Item".

In the template for Long Term Projects, the Program Items that have that particular Long Term Project defined in the "Long Term Project" custom field are shown with that Long Term Project.
It is this that works for the English version, but not for the Dutch version.

Hope this clarifies.

May 16, 2019 at 7:32 am #3822627

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Can you point me to the file/files (names, directories, line of code interested) that are handling the loop that should be visible in this page (but it's not, right now):
hidden link

That would probbly help me check the process and see if there's something there that is off.

In the meantime, you could do a var_dump on the results of the same page in both the english page and the dutch page, because i can only guess that the ID of the posts type are not changing throughout the languages (that's why you probably are not getting results in the dutch page, because the ID are the ones from the English site)

Let me know how it goes.

May 20, 2019 at 12:46 pm #3846951

babakF-3

Not sure I fully understand your request.

The theme file that displays the page in question is single-long_term_project.php. The loop is called like so:

while ( have_posts() ) : the_post();

Inside the loop, this picks up the related program items:

$args = array(
'post_type' => 'program_item',
'orderby' => 'meta_value',
'meta_key' => 'start_datetime',
'nopaging' => true,
'order' => 'DESC',
"suppress_filters" => false,
'meta_query' => array(
array(
'key' => 'long_term_project',
'value' => '"' . get_queried_object_id() . '"',
'compare' => 'LIKE'
),
)
);
$events = new WP_Query( $args );

get_queried_object_id() returns the correct id for the long term project in both Dutch and English. Both versions properly have multiple program items associated with them (which are shown with the English long term project, but not with the Dutch).

Let me know what else you need to make an informed analysis.

May 21, 2019 at 11:33 am #3854835

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Thanks for the information,

The last thing i mentioned on my last reply was to do a var_dump on that loop (which was the one that you probably didn't undertstand, and i apologize if i didn't make myself clear earlier)

Documentation: hidden link

The var_dump() function will help in isolating this problem and at least know where in the code is something going wrong.

Summarizing:
So far we know the loop seems to be returning an empty list, or nothing at all for one of the languages.

I suspect the problem is coming from that loop, but by making the var_dump we will see if the ID's are being retrieved correctly or not (i'd start with using that var_dump() in get_queried_object_id() and then in the WP_Query() function ).

That will probably show us what's going on.

I hope i explained myself clearer now, let me know how it goes.

May 23, 2019 at 1:19 pm #3875697

babakF-3

Hi again.

The mystery deepens. The Dutch 'Long Term Project' now shows one 'Program Item'. But, the translated version of that Program Item is not showing in the English translation of the Long Term Project.

Dutch:
hidden link
English:
hidden link

When you say you want a var_dump *in* particular functions, I am assuming you want the var_dump of the result of those functions.

I've added the var_dumps to the pages above, for the two functions you request. These results are only visible to admins of the site.

May 24, 2019 at 3:03 pm #3885961

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Hello,

I created this small revision post in one of our sandboxes which might help you debug the issue. You can log in here: hidden link

And then you can check out the revision i made for you, in here:
hidden link

I made a small video of a query that might be worth checking into: hidden link

I don't really know how it works and debugging falls out of the scope of our support ( https://wpml.org/documentation/privacy-policy-and-gdpr-compliance/ ) but i thought this could be an interesting way to compare both codes and check for discrepancies.

Another thing i can suggest is that you try to find out the posts ID that do work and try to find them in the var_dump, that way you can compare what's different between them and figure things out, because the cause of the problem is most likely inside one of those arrays/queries

I'm here for further questions or doubt about this matter, and i'll do my best to at least point you in the right direction.

Regards.

May 24, 2019 at 4:54 pm #3886501

babakF-3

Thanks for the elaborate response!

Somewhat sadly, it didn't put me on the right track (I'm quite sure I'm not using hooks that affect the discrepancy in the query you highlighted). But, I did make sufficient progress.

This *was* my meta_query, for trying to match program items with the current long term project:

'meta_query' => array(
array(
'key' => 'long_term_project',
'value' => '"' . get_queried_object_id() . '"',
'compare' => 'LIKE'
),
)

I found that if I changed it to the following, *all* program items that were supposed to match, and only those, did match:

'meta_query' => array(
array(
'key' => 'long_term_project',
'value' => get_queried_object_id(),
'compare' => 'LIKE'
),
)

Note the removal of quotes around get_queried_object_id().

I'm quite sure that this change should not make a difference, but it does. In exactly the way that resolves my problem.

So, now, I use the adjusted meta_query and, when looping over the program items, confirm that a connected long term project matches the current long term project (as it's theoretically possible that long term projects with longer IDs that contain the ID of the current long term project are also matched).

Thanks for the help!

May 24, 2019 at 6:20 pm #3887027

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

It's interesting, it appears that the return value was somehow a string, i can see the value is ""17489"" in one of the loop runs for example, so, note the double quotes. the value is a string and not an ID which is something i did not expect. The most interesting part is that it still worked on one of the languages, so i wonder what could be the difference between the 2 iterations.

Sadly, that's a bit beyond my knowledge but i'm very glad you figured it out!

If you feel the problem is resolved, then may i ask you to set the ticket as resolved or give me confirmation so i can do it for you?

Thanks and in the meantime i wish you a lovely weekend.

May 24, 2019 at 6:22 pm #3887045

babakF-3

My issue is resolved now. Thank you!

(And, I agree, I'm also a bit baffled as to why this is working the way it is.)