Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multilingual default Jobs page not translatable with WPML and WP Job Manager #2354

Open
1 task
Shahraz98 opened this issue Dec 18, 2022 · 2 comments
Open
1 task

Comments

@Shahraz98
Copy link

Describe the bug
For our project, we use WPML in combination with WP Job Manager. As you know, a default jobs page can be set where all of the job widgets (such as filters) and the job listings will appear. In our case, this page is called "Stellenangebote" ("Jobs" in german), which has been translated with WPML and has the following urls: "www.websitename/stellenangebote" (in german) and "www.websitename/it/offerte-di-lavoro" (in italian). The [jobs] shortcode is added in both versions of the page. In german, which is the website's main language (set through WPML), everything is working fine. On the same page, we also have a language switcher, which can switch to the italian version of the page on click. But when a user clicks on the switcher, instead of going to the translated url ("www.websitename/offerte-di-lavoro") it goes to "www.websitename/it/stellenangebote", which is a page that does not even exits. On "www.websitename/it/stellenangebote", everything still works fine, but if we click on the "Offerte di lavoro" page from the main menu, it goes to the page "www.websitename/it/offerte-di-lavoro", which looks broken and has no job widgets (although it does have a job list with default styling).

Our objective is to have one page with different slugs in different languages. So, when a user is on "www.websitename/stellenangebote" and clicks on the language switcher, it should be directed to "www.websitename/it/offerte-di-lavoro", where the job widgets, styling, and list should appear and function exactly like in the german version.
We tried looking through your plugin's code, and, as disclosed in the following thread ( #786 ), the issue should have been fixed and the plugin should be compatible with WPML as of now. So we don't understand what we've been doing wrong.

To Reproduce
Steps to reproduce the behavior:

  1. Install WPML and WP Job Manager Plugins
  2. Add a main and a secondary language to the website
  3. Create some Jobs
  4. Create and set a Jobs page (add [jobs] shortcode + add this page as the default Jobs page by clicking in admin menu on Jobs -> Pages -> Jobs page)
  5. Create a translation of the Jobs page (click on the '+' near the page's title) for the secondary language
  6. Change the url slug of the translated page (set anything, as long as it is different from the slug of the Jobs page in the main language)
  7. Add a Job widget, f.e. a filter for a job category
  8. Navigate to the default Jobs page in main language, everything should work fine and widget should be visible
  9. Navigate to the url of the translated Jobs page, here wordpress does not show the widget and the page is styled as a default archive page
  10. If you see a language switcher when on the main Jobs page, by clicking on the switcher you will be redirected to 'base url/secondary language code/same slug as the main jobs page'.

Expected behavior
By clicking the switcher, the user should be redirected to the url of the translated version of the jobs page. In addition, job widgets and styling should remain unchanged.

Isolating the problem (mark completed items with an [x]):

  • [X ] I have deactivated other plugins and confirmed this bug occurs when only WP Job Manager plugin is active.
  • This bug happens with a default WordPress theme active.
  • [ X] I can reproduce this bug consistently using the steps above.

WordPress Environment

  • WordPress Version: 6.1.1
  • WP Job Manager Version: 1.39
  • PHP Version: 7.4
@mikeyarce
Copy link
Member

Testing using WPML 4.6.0 - what I found is that the AJAX request to retrieve the jobs ends up being a 400 and so the job listings never populate:

YU0ag4.png

I see this error message in the request: A variable mismatch has been detected

@diiegopereira
Copy link

Hi there, this is Diego from the WPML compatibility team.

The issue happens because the plugin is registering the post type slug dynamically:

$rewrite = [
	'slug'         => $permalink_structure['category_rewrite_slug'],
	'with_front'   => false,
	'hierarchical' => false,
];

This tends not to work very well with WPML, as it needs a static slug to be able to translate it.

With a static slug, you should be able to translate it in WPML > Post Types Translation screen.

Workaround

  • Open the app/public/wp-content/plugins/wp-job-manager/includes/class-wp-job-manager-post-types.php file
  • Inside /WP_Job_Manager_Post_Types::register_post_types(), around line 278, replace hte following line:
$permalink_structure = self::get_permalink_structure();
  • With:
$permalink_structure = self::get_permalink_structure();

// WPML Workaround for compsupp-7570
if( class_exists( 'Sitepress' ) ) {
	$permalink_structure["job_rewrite_slug"] = 'job';
}
  • Re-save permalinks

We created the following errata for this: https://wpml.org/errata/wp-job-manager-job-incorrect-slug-translation-for-job-listings/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants