Skip Navigation

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

Problem:
You are using WP-CLI to list all media IDs in the trash across all languages but the command only returns media IDs for the main language.
Solution:
We have identified two potential workarounds to include media IDs from all languages:
1) Use the WP-CLI parameter

--suppress_filters=true

which allows the command to work across all languages.
2) Use the parameter

--url="https://yourwebsite.com/en"

to force WP-CLI to work in the language based on the URL.

Additionally, our 2nd Tier Support suggests modifying the code in

wp-content/plugins/sitepress-multilingual-cms/classes/query-filtering/wpml-query-filter.class.php

. Replace the existing

posts_where_filter

function with the following code to include a condition that checks for the 'lang' parameter in the query:

public function posts_where_filter( $where, $query ) {
	if ( $query === null || $this->where_filter_active( $query ) === false ) {
		return $where;
	}

	$requested_id = isset( $_REQUEST['attachment_id'] ) && $_REQUEST['attachment_id'] ? $_REQUEST['attachment_id'] : false;
	$requested_id = isset( $_REQUEST['post_id'] ) && $_REQUEST['post_id'] ? $_REQUEST['post_id'] : $requested_id;
	$requested_id = (int) $requested_id;

	$default_language = $this->sitepress->get_default_language();

	$post_language = $this->post_translations->get_element_lang_code( $requested_id );
	if (isset($query->query["lang"])) {
		$post_language = $query->query["lang"];
		$requested_id = "1"; //hack needed because then $current_language will not get the $post_language, but will call for get_current_language
	}

	$current_language = $requested_id && $post_language ? $post_language : $this->sitepress->get_current_language();

	$condition = $current_language === 'all' ? $this->all_langs_where() : $this->specific_lang_where( $current_language, $default_language );
	$where     .= $condition;

	return $where;
}

Please note that this solution might be outdated or not applicable to your specific case. We highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If these solutions do not resolve your issue, please open a new support ticket at WPML support forum.

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 16 replies, has 2 voices.

Last updated by Kor 3 weeks, 1 day ago.

Assisted by: Kor.

Author Posts
November 5, 2024 at 10:39 am #16365449

Dimitri

Hello,

I've find also 2 workarounds:

1) It looks like the wp-cli parameter --suppress_filters=true allow to work in all languages.
2) the parameter --url="https//mywebsite.com/en" force wp-cli to work in the language based on the url. Or --url="en"

Regards,

November 5, 2024 at 10:41 am #16365453

Kor
Supporter

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for sharing your workarounds. Anything else that you'd like to share with our 2nd Tier Support before I close this ticket?