Multisite-Language-Switcher icon indicating copy to clipboard operation
Multisite-Language-Switcher copied to clipboard

Custom post type and Custom taxonomy linking problem

Open hatsumatsu opened this issue 9 years ago • 21 comments

I have a setup of two languages in a Wordpress Multisite environment, based on paths:

Main language: http://example.com/ Second Language: http://example.com/en/

When I register a custom post_type width slug => "my_post_type" I get the achive pages:

Main language: http://example.com/blog/my_post_type/ Second language: http://exmaple.com/en/my_post_type/

(Note the /blog/ permalink fragment, that should stay there following the WP Codex http://codex.wordpress.org/Before_You_Create_A_Network )

This results in the language switcher to point me to http://example.com/my_post_type/ when switching from the second language to the main language, missing the /blog/ part of the URL or to http://example.com/en/blog/my_post_type/. Both throw an 404. Same behavior occurs on custom taxonomy archives.

hatsumatsu avatar Aug 14 '14 14:08 hatsumatsu

Go to the permlinks settings after creating a new post_type. Let me know...

lloc avatar Aug 15 '14 10:08 lloc

I updated permalinks settings after registring the post type, permalink structure is set to /%postname%/ on both sites. I produced a reduced test case and the bug still appears:

  • fresh wordpress install under http://multilanguage.local/
  • no plugins
  • setting permalinks to /%postname%/
  • Creating a sub-directory based Network following http://codex.wordpress.org/Create_A_Network
  • Creating a second site in the network under http://multilanguage.local/en/
  • Installing a simple theme that registeres a post type with 'rewrite' => array( 'slug' => 'projects' )
  • Checking and updating permalink settings on both sites (still /%postname%/)
  • now the main sites post type archives lives under http://multilanguage.local/blog/projects/, the archive of the second site under http://multilanguage.local/en/projects/
  • Using the Multisite Language Switcher widget to switch from one language to another on these archives points either to http://multilanguage.local/en/blog/projects/ (main site > second site) or http://multilanguage.local/projects/. Both trow an 404.

hatsumatsu avatar Aug 15 '14 12:08 hatsumatsu

Strange ... I will try to reproduce that when I'm back at home (next weekend).

lloc avatar Aug 16 '14 08:08 lloc

Could you reproduce the problem?

hatsumatsu avatar Aug 28 '14 11:08 hatsumatsu

Yes, after playing a little bit with WordPress 4.0 I had the same issue.

lloc avatar Aug 28 '14 13:08 lloc

This should do the trick https://github.com/lloc/Multisite-Language-Switcher/commit/8821ef11f269420452270f380e3d9c338275e584

Let me know, Dennis.

lloc avatar Sep 01 '14 13:09 lloc

thanks for the fix!

hatsumatsu avatar Sep 03 '14 06:09 hatsumatsu

I think the bug is only fixed in parts: Switching between languages on Custom Post Type archives and Custom Taxonomy term archives works well. But going to another language on a single post view of a custom post type still doesn't work.

hatsumatsu avatar Sep 12 '14 17:09 hatsumatsu

The fix is just for taxonomies where the get_term_url relies on $wp_rewrite. MSLS uses get_permalinks for all post_types where this problem should not exists. Could you double-check this please?

lloc avatar Sep 17 '14 13:09 lloc

Ich checked it again in my testing environment, the connection between single views of custom post types (posts and pages work well) seems somehow broken:

Sticking to my example above, a single view in the main site is located under http://multilanguage.local/blog/projects/projekt-deutsch/. In this view the language switcher points to the connected post under http://multilanguage.local/en/blog/projects/project-english/ (notice the wrong /blog/ part of the URL). The second site's post is found under http://multilanguage.local/en/projects/project-english/ but the language switcher points to http://multilanguage.local/projects/projekt-deutsch/ (here the /blog/ part is missing).

I'm using v.1.0.1 of the plugin from github and WP 4.0

hatsumatsu avatar Sep 18 '14 07:09 hatsumatsu

Is the custom post type projects registered with hierarchical set to true or false?

lloc avatar Sep 18 '14 08:09 lloc

Not defined, so defaults to false. Here is my Custom post type and taxonomy setup: https://github.com/hatsumatsu/Port-F/blob/master/functions.php#L109

hatsumatsu avatar Sep 18 '14 09:09 hatsumatsu

Maybe this is useful too: http://wordpress.stackexchange.com/questions/133498/remove-multisite-blog-slug-from-specific-custom-post-type ... I will test a little bit more because I'd like to understand if this should be corrected in the core or in the plugin. In my opinion get_permalink should act always in the same manner.

lloc avatar Sep 18 '14 10:09 lloc

Thanks for the hint and your effort, but it turns out to add even more complexity to the issue: I added 'with_front' => false to the rewrite array both in register_post_type()and register_taxonomy() to get rid of the odd /blog/slug in the URLs on the main site. After refreshing the permalink settings on both sites the connection between single views of custom post types works, but it breaks the connection between custom post type archives and custom taxonomy term archives in one direction:

  • on http://multilanguage.local/projects/ (main site) the language switcher points to http://multilanguage.local/en/projects/ : Works
  • on http://multilanguage.local/en/projects/ (second site) the language switcher points to http://multilanguage.local/blog/projects/: Fails

Same issue occurs on custom taxonomy term archives. I guess it all comes down to this odd hard-coded behavior of the WP core to add the /blog/ slug (only) to the main site's URLs...

hatsumatsu avatar Sep 18 '14 18:09 hatsumatsu

just curious, any news on this issue?

hatsumatsu avatar Nov 04 '14 14:11 hatsumatsu

I plan to write an add-on (like MslsMenu) that can manage the localized slugs and offers inputs for correcting the $wp_redirect-rules.

lloc avatar Nov 04 '14 16:11 lloc

Hi lloc,

Thank you for your great work. I see this issue is still open and it's seems I have the same problem.

I have set custom permalink to /news/%postname%/ for my two sites (the /blog/ part was removed) :

  • mysite.local/news/
  • mysite.local/fr/news/

I have a /news/ archive page set as Posts page in Reading Settings, and posts like this :

  • mysite.local/news/my-post

The Msls links correctly the news archive page and the post pages.

However I have some custom post types archive pages like /services/, and there I have this :

  • mysite.local/services/ links to mysite.local/en/services/ = OK
  • mysite.local/en/services/ links to mysite.local/news/services/ = NOK

When I look the register_post_type, there is the rewrite argument with the with_front parameter set to false.

There may be something I have not done properly ? Thank for your time.

giovannetti-eric avatar Jul 14 '15 06:07 giovannetti-eric

Hi, just checking back on this issue. Is there anything we can do to help solving this?

hatsumatsu avatar Jul 07 '16 08:07 hatsumatsu

Is this still an issue?

s-a-s-k-i-a avatar Sep 12 '17 18:09 s-a-s-k-i-a

There is a function active in the plugin's options that should show you if there are any translations active.

lloc avatar Sep 13 '17 10:09 lloc

Hi, i'm experiencing the issue @hatsumatsu described with the custom taxonomy terms losing links in one direction. And is this an issue with WP core, or should msls handle this?

And for now the work-around would be keep using /blog/ on the main site?

stijnjanmaat avatar Feb 06 '18 19:02 stijnjanmaat