[Feature Request] WP-CLI works only with main languages Posts
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
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.
Background of the issue:
I am trying to use WP-CLI to list all media IDs in the trash across all languages. I used the command: wp post list --post_type='attachment' --post_status=trash --format=ids.
Symptoms:
The command only returns a list of media IDs in the trash for the main language, not for all languages.
Questions:
How can I modify the WP-CLI command to include media IDs from all languages?
Is there a setting in WPML that affects how WP-CLI retrieves media IDs?
Here is the ticket. I will need to closely examine your website. Therefore, I will require temporary access (WP-Admin and FTP) to a test site where the problem has been replicated, if possible. This will enable me to provide better assistance and determine if any configurations need to be modified.
Please note that it is important to have a backup for security purposes and to prevent any potential data loss. You can use the UpdraftPlus plugin (https://wordpress.org/plugins/updraftplus/) to fulfill your backup requirements.
Your upcoming reply will be treated with confidentiality and will only be visible to you and me.
✙ To resolve the issue, I may need your consent to deactivate and reactivate plugins and the theme, as well as make configuration changes on the site if necessary. This emphasizes the significance of having a backup.
Could you please check on a basic sandbox website ? My website contains copyright code and tons of images.
It is easier to check this on an empty sandbox site.
Sorry, we do not have a sandbox site that we can use to run WP-CLI commands. Could you prepare a sandbox site from your end and also, share access where we can run the WP-CLI commands together?
I can see the issue now. --lang=en filter doesn't seem to work or exist. I need to check with our 2nd Tier Support about this and I will come back to you as quickly as possible.
Our 2nd Tier Support checked and they found a workaround by replacing wp-content/plugins/sitepress-multilingual-cms/classes/query-filtering/wpml-query-filter.class.php