Skip to content

Instantly share code, notes, and snippets.

@tanjimahmmed
Last active February 28, 2020 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanjimahmmed/90fd66181c177a62add36ad15a439dde to your computer and use it in GitHub Desktop.
Save tanjimahmmed/90fd66181c177a62add36ad15a439dde to your computer and use it in GitHub Desktop.
slug link change
function philosophy_cpt_slug_fix($post_link, $id){
$p = get_post($id);
if(is_object($p) && 'chapter'==get_post_type($id)){
$parent_post_id = get_field('parent_book');
$parent_post = get_post($parent_post_id);
if($parent_post){
$post_link = str_replace("%book%", $parent_post->post_name,$post_link);
}
}
return $post_link;
}
add_filter('post_type_link', 'philosophy_cpt_slug_fix', 1,2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment