I have a custom post type named course
. I added rewrite rules so I can include post_meta data in the URL.
/* Rewrite URLs for generate dynamic template */
add_filter( 'generate_rewrite_rules', 'courses_rewrite_rules' );
function courses_rewrite_rules($wp_rewrite) {
$wp_rewrite->rules = [
'cursos/([^/]+)/([^/]+)/([^/]+)/?$' => 'index.php?post_type=courses&unity=$matches[1]&formation_type=$matches[2]&courses=$matches[3]',
'cursos/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$' => 'index.php?post_type=courses&unity=$matches[1]&formation_type=$matches[2]&courses=$matches[3]&grade=$matches[4]',
] + $wp_rewrite->rules;
return $wp_rewrite->rules;
}
It works as expected when I try to access the link through the browser. It also shows correctly in the post editor:
However, if I use the function get_permalink()
or get_permalink
, instead of http://dev.unasp.edu.br/cursos/virtual/graduacao/letras-licenciatura/
, it’s returning http://dev.unasp.edu.br/cursos/letras-licenciatura/0
.