Skip Navigation

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 ericH-23 1 day, 18 hours ago.

Assisted by: Andreas W..

Author Posts
December 22, 2024 at 8:57 pm #16538895

ericH-23

Background of the issue:
I am working on a site under development and trying to implement a resume count limit using WPML. I added this code: https://wpml.org/forums/topic/jobmanager-resume-limit-count-is-false/ to manage the resume count limit. The code works in the standard language, hiding the add resume button when the limit is reached.

Symptoms:
The resume count limit is not working in the second language. The add resume button is shown despite the limit being reached.

Questions:
Why is the resume count limit not working in the second language?
How can I ensure the resume count limit works across all languages?
This is in my system, can you pelase check it on your side, whether you have the same result/error?

December 24, 2024 at 12:33 pm #16543669

Andreas W.
Supporter

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

Timezone: America/Lima (GMT-05:00)

Hello,

Please take a backup of your site and then test the following workaround instead:

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>'; 
    }
}

Take note, that this workaround sets the limit to 5 inside the function resume_manager_add_resume_button() at:

$limit = 5;

If this will not solve the issue, I will be glad to provide a WPML test site, on which we can recreate the issue and work on a solution.

Best regards
Andreas

December 31, 2024 at 6:11 pm #16556414

ericH-23

Hi,
Let me check this code in the next days. This I am writing so that the ticket is not closed now. Thanks, kind regards
Eric

December 31, 2024 at 7:28 pm #16556431

Andreas W.
Supporter

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

Timezone: America/Lima (GMT-05:00)

Hi Eric,

The ticket will remain open for two weeks. I will be awaiting your next reply as soon as possible.

Best regards
Andreas

January 1, 2025 at 4:34 pm #16557303

ericH-23

Hi,
Thanks, I checked this now and the hiding of the button is working, so with this workaround it is possible to limit the resumes.
Now I hope on take over in the basic code by WP Jobmanager.
Thanks, kind regards - and a Happy New Year!
Eric