Background of the issue:
I am trying to run an import script, but it fails every time. The script throws a fatal error related to the array_filter function. The error message is: Fatal error: Uncaught TypeError: array_filter(): Argument #1 ($array) must be of type array, false given in wp-content/plugins/sitepress-multilingual-cms/classes/translation-jobs/class-wpml-element-translation-package.php:463. According to the get_post_meta documentation, false will be returned for invalid post_ids and should be handled accordingly to prevent a fatal error.
Symptoms:
The import script fails every time it runs, throwing a Fatal error: Uncaught TypeError: array_filter(): Argument #1 ($array) must be of type array, false given.
Questions:
Why does the import script fail with the error: array_filter(): Argument #1 ($array) must be of type array, false given?
Is the workaround provided a valid solution to handle the false return value from get_post_meta?
I have implemented my own workaround, which functions, changing the line 463 to:
$custom_fields_values = array_values( array_filter( get_post_meta( $post->ID, $key ) ?: [] ) );
I would request for you to implement this.
In an earlier ticket, you responded with the request to use the 'delete all ghost items' on your troubleshooting page. This does not fix the issue for me, unfortunately.
This is very odd.
Normally the function \WPML_Element_Translation_Package::add_custom_field_contents takes a post that already exists and generates a package based on its meta fields.
In that sense, get_post_meta will never return false, because the post is supposed to exist at this point and hence the ID won't be invalid.
I understand that a defensive fix would solve this, but I feel that there might be something more here to the case and I would feel better we can have a package and to trace the issue.
Can you please provide us with a copy of your site so we can take a deeper look? In case you do, I enable a private reply so you can share safely a download link. A copy of the DB and the wp-content folder (excluding uploads) will do or you can use “Duplicator” or "All in One WP Migration" plugins.