1

Is there any way to have a permalink begin with a custom post field? For example, the follow works:

  • $wp_rewrite->add_permastruct('solicitors', '/anything/%custom_field%/%custom_field_2%', false);

But this doesn't:

  • $wp_rewrite->add_permastruct('solicitors', '/%custom_field%/%custom_field_2%/', false);

It seems that every page aside from city pages get redirected to the homepage when the custom field placeholder is placed first. When a manual text item (such as 'anything) is placed first, it works, but that is not what our structure needs to be. Any ideas?

  • 2
    it's possible, but complicated. WordPress has no way of knowing if the request is for your custom post or a parent/child page, since the pattern is the same, so you'll either have to intercept the query parsing and check if it's an existing custom post and modify the query vars accordingly, or you'll have to add a unique rewrite rule for every custom post you insert. it's far simpler to just prefix those URLs with something unique. – Milo Nov 8 '13 at 21:57
  • Good input. I may look into those two, since we need that url structure. I'll post back here with a more exact solution if I can get it working. – Daniel Nov 9 '13 at 22:02
  • Haven't figured it out yet. Milo - Can you elaborate a bit more on all of this? If anyone else has any input as well that would be very helpful. – Daniel Nov 10 '13 at 0:26

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.