Skip Navigation

[Resolved] Post Type Custom URL 400 Error – ../[post-type]/%post_id%/

This thread is resolved. Here is a description of the problem and solution.

Problem:
the user has a wrong URL generated in the permalinks because he uses a special permalink structure for the custom post type.

Solution:
URLs and permalinks are out of the scope of the Toolset plugin. A workaround can be implemented using Javascript that will correct the URL at the browser.

This support ticket is created 4 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by danG-2 4 years, 2 months ago.

Assisted by: Jamal.

Author
Posts
#1960619

The yoast breadcrumb plugin auto links to the custom post type archive page but because I have set a custom URL for the post type I am getting a 400 error on the index link e.g. hidden link.

I've tried applying a 301 redirect at server level but this doesn't appear to resolve the issue. How can I stop this issue occuring so I can link to the relevant archive / index page?

#1961565

Hello and thank you for contacting the Toolset support.

Can you elaborate more on I have set a custom URL for the post type? Did you do it using custom code? Using a 3rd party plugin?

Can you share the URL of the archive page or a page where these erroneous links exist? I would like to know more about this issue.

In the meantime, when you change the permalinks structure using the add_permastruct you will also need to add a filter to change the link of posts using the  filter. Check this SO reply https://wordpress.stackexchange.com/a/253325
- https://developer.wordpress.org/reference/functions/add_permastruct/
- https://developer.wordpress.org/reference/hooks/post_type_link/

Finally, I would like to know, what permalink structure do you want to have? Or if you need the Yoast generated links to be different?

#1961593

Hey Jamal

Appreciate the response.

Let me try to address your questions:

- I amended the permalink using the option within the custom post setup options in toolset. For example rather than 'Players' having a permalink of ../player/[player name] it becomes ../player/[post-id]/[player name]
- The actual player permalinks work fine (e.g. hidden link) as does the index if I go to hidden link but for some reason the yoast breadcrumbs URL for the index defaults to hidden link (you see this live on the text above 'Alyssa Valdez' h1 on hidden link.

I think perhaps it is the filter that you referenced that I am perhaps missing.

#1961665

If I understand well, you are talking about the link "Players", right? This one hidden link right?

It seems to me that this comes from the Yoast plugin, Toolset is not involved in the generation of that link. So, I'll suggest that you reach to the Yoast team to report this issue.

From our side, we can suggest a Javascript workaround. Add the following snippet to your website. Or, if you are using a content template for Players, add it to the content template. It will remove the "%post_id%/" from the link:

jQuery(function($){
  $('#breadcrumbs a').attr('href', $('#breadcrumbs a').attr('href').replace('%post_id%/', ''))
})

I hope this helps. Let me know if you have any questions.

#1961765

My issue is resolved now. Thank you!