I need to support permalink URL structure like:


(city, course type etc. are taxonomies).

If there would be unique slug within these links I could do something like:

add_action('init', 'custom_permastruct_rewrite');
function custom_permastruct_rewrite() {
  $wp_rewrite->add_rewrite_tag("%some_slug%", '([^/]+)', "name=");
  $wp_rewrite->add_permastruct('course_link', '/adult-course/newyork/language-course/english/%some_slug%', false);

...but there's not :(

On the other hand I can also do something like:

add_action('init', 'custom_rewrite_basic');
function custom_rewrite_basic() {
    add_rewrite_rule( --preg_expression_here--, --redirect_address_here, 'top');

...which works, but the address is "rewritten" as the function name says and I get redirected from the original URL so: http://example.com/adult-course/newyork/language-course/english/standard to something like for instance http://example.com/course/my-unique-slug

  • Rewriting and redirecting are not the same thing. If your rewrite rule results in a redirection, it's not working. – Milo Apr 27 '17 at 16:13
  • I know that they are different things and that now it is not working. I'm asking if it can be done in Wordpress without rewriting the Wordpress core, and if someone could suggest some solution :) – Picard Apr 27 '17 at 19:47
  • Sure you can do it without rewriting core. All that needs to be done - is correctly written rewrite rule. – Butuzov Apr 28 '17 at 11:49
  • add_rewrite_rule will redirect me to the default URL or is there a way to prevent it? $wp_rewrite->add_permastruct on the other hand needs a unique name= and I would need to look up the post by type && city && course-leve etc. and from my research it looks like it cannot be done using add_permastruct + add_rewrite_tag – Picard Apr 28 '17 at 12:05

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.