This thread is resolved. Here is a description of the problem and solution.
Problem:
The client is implementing a resume count limit on a multilingual site using WPML. The limit works in the default language but fails in the second language, showing the 'Add Resume' button even when the limit is reached.
Solution:
We recommend taking a backup of your site and testing the following code to ensure the resume count limit works across all languages:
function resume_manager_count_user_resumes( $user_id = 0 ) { global $wpdb; if ( ! $user_id ) { $user_id = get_current_user_id(); } // Check if WPML is active if ( defined( 'ICL_LANGUAGE_CODE' ) ) { // Get the default language code $default_language = apply_filters( 'wpml_default_language', null ); // Query to count resumes across all languages (including translations) return $wpdb->get_var( $wpdb->prepare( " SELECT COUNT(DISTINCT p.ID) FROM {$wpdb->posts} p LEFT JOIN {$wpdb->prefix}icl_translations t ON p.ID = t.element_id WHERE p.post_author = %d AND p.post_type = 'resume' AND p.post_status IN ( 'publish', 'pending', 'expired', 'hidden' ) AND ( t.language_code = %s OR t.source_language_code IS NULL ) ", $user_id, $default_language ) ); } // Default query if WPML is not active (only counts resumes in the default language) return $wpdb->get_var( $wpdb->prepare( " SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_author = %d AND post_type = 'resume' AND post_status IN ( 'publish', 'pending', 'expired', 'hidden' ); ", $user_id ) ); } // Check if the resume limit is reached and remove the "Add Resume" button function resume_manager_add_resume_button( $user_id = 0 ) { $limit = 5; // Set the resume limit (this could be dynamic or configurable) $resume_count = resume_manager_count_user_resumes( $user_id ); if ( $resume_count >= $limit ) { // Add custom code to hide or disable the "Add Resume" button echo '<style>#add_resume_button { display: none; }</style>'; } }
If this solution does not resolve the issue, we can provide a WPML test site to further investigate and solve the problem.
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 the issue persists, 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 3 replies, has 0 voices.
Last updated by 1 week, 2 days ago.
Assisted by: Andreas W..