0

I have a series of pages with the heirarchy:

/albums /name1 /name2 /name3

ie. all these pages have a parent page with the slug 'albums'.

If I have a permalink /name2 it shows the page /albums/name2. I didn't need to fully express the link as /albums/album2

I also have a post_type called 'songs' which is not hidden, but would be far less often visited.

/songs/name1 /songs/name2 /songs/name3

So there are Pages and 'Songs' with the same slug. In the past, simply typing

mysite.com/name2 would bring up the -Page- (ie. /albums/name2), not the Song. This has changed. Now, if I type:

mysite.com/name2 into the browser, /songs/name2 appears.

So the precedence of 'Songs' appears now to be higher in the redirection 'hierarchy'.

How can I change it back to the way it was... ie. when a visitor types:

mysite.com/name2 into the browser, the -Page- /albums/name2 appears?

I have experimented with all number of values for the Rewrite array to no avail for the simple reason that it's not the permalink that is the issue, it is the fact that in the WP_Rewrite Rules, the 'Songs' post_type is processed -first- for some reason, so if there are two posts with the same slug, one 'Page' and the other 'Song', the Song will be rendered.

I have been working around this by simply setting the Public property for 'Songs' to false, but that's no long term solution.

Help!

  • 1
    I don't think it's rewrite rule precedence, the requests don't match the song URL pattern. WordPress is guessing what it thinks is the correct post because the original request is a 404. This isn't a particularly efficient way to handle things, I question why exactly you require this behavior at all. – Milo Jul 9 '14 at 18:53
  • Well, if you have any ideas as to where in the WP core this decision -is- being made, I'd appreciate hearing it. No it's not 'efficient' but visitors will expect that when they type /name2 it will come up with /albums/name2 and NOT /songs/name2. And this is how it 'worked' up until recently.. I don't know exactly when this behaviour changed. It's more 'SEO' than anything else... and also I don't want to have to explicitly redo all the links which previously worked. – jchwebdev Jul 9 '14 at 20:12
  • 1
    It happens in wp-includes/canonical.php. The fact that this used to work was basically an accident, not a consistent feature. I don't think anything has changed other than the order in which songs and albums happen to be in your database. – Milo Jul 9 '14 at 20:22
  • You're a genius. The relevant function is, in fact, redirect_guess_404_permalink() and it works as you say: there is no way to set the precedence of the SQL query. Is there a way to override (or replace) this function or module without hacking the core? – jchwebdev Jul 9 '14 at 22:13
  • 1
    you can add a filter to redirect_canonical, catch those redirects and send them somewhere else, or you can remove and replace the entire redirect_canonical function with remove action. – Milo Jul 9 '14 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.