KLicheR / wp-polylang-translate-rewrite-slugs

Wordpress plugin to help translate post types rewrite slugs with the Polylang plugin.
110 stars 45 forks source link

Children Permalink without parent slug #23

Closed asier-laukoa closed 9 years ago

asier-laukoa commented 9 years ago

Hi,

I am getting a 404 error only in child custom posts, because the rewrite filter seems to delete parent post from children permalink.

So mydomain.com/custom-post-type-slug/parent-custom-post is working in every languages but when I try to get the permalink of a "custom post child" the permalink is mydomain.com/custom-post-type-slug/child-custom-post instead mydomain.com/custom-post-type-slug/parent-custom-post/child-custom-post

Any help will be apreciated. Thanks a lot!

l364cyv1 commented 9 years ago

@asier-laukoa Have you solved this maybe because I have the same issue and I really need to find a fix?

asier-laukoa commented 9 years ago

Hi @stefaneli31,

No I haven't. Finally, I decided to build the problematic URLs by myself in the templates, the menus and the submenus.

l364cyv1 commented 9 years ago

I have added this line $post_parent = get_post($post->post_parent); and added to return variable this ($post->post_parent?$post_parent->post_name.'/':"") in post_type_link_filter and it worked. However now I have issue with the permalink on Edit Screen. I will try to fix this issue with hook like get get_sample_permalink_html in functions.php :(

tanelkarp commented 9 years ago

I was experiencing the same issue and found the cause and a possible solution.

https://github.com/KLicheR/wp-polylang-translate-rewrite-slugs/blob/master/polylang-translate-rewrite-slugs.php#L191

When creating permalinks, the plugin currently constructs them by combining them as "home url + the new rewrite slug + post title". Meaning it doesn't even try to include the parent pages, if there are any. As a solution one could use the "get_page_uri" function to retrieve the post uri together with parents and use this instead of the post title.

So, the line 191 would look like this:

return home_url('/'.$this->post_types[$post->post_type]->translated_slugs[$lang]->rewrite['slug'].'/'.($leavename?"%$post->post_type%":get_page_uri( $post->ID )));

Tested this on my install and it seems to work.

asier-laukoa commented 9 years ago

It seems to be a good solution. I will try it at my installation too.

Thanks a lot!

asier-laukoa commented 9 years ago

It worked like a charm, jejeje!

Just a final question. Is because this plugin that my Custom Post Type Permalinks are not ending with the trailing slash "/" when I get the permalink with "the_permalink()" function? Because I need to have my permalinks with that final trailing slash, any idea?

Thanks a lot!

KLicheR commented 9 years ago

I think I use the user_trailingslashit function for when you use get_post_type_archive_link and get_term_link functions which is supposed to follow your blog's settings about the trailing slash. But it's not used in the replace_permastruct function, when the module add permastructs...

I unfortunately don't have time to work on that but I hope it's a good starting point if you want to try to fix it.

asier-laukoa commented 9 years ago

Ok, thank you for the lead, I will work from there.

Great job with this plugin, thanks!

asier-laukoa commented 9 years ago

Done,

I've just changed the line 191 (https://github.com/KLicheR/wp-polylang-translate-rewrite-slugs/blob/master/polylang-translate-rewrite-slugs.php#L191), such as here:

return trailingslashit(home_url('/'.$this->post_types[$post->post_type]->translated_slugs[$lang]->rewrite['slug'].'/'.($leavename?"%$post->post_type%":get_page_uri( $post->ID ))));

Thanks!