Last active
December 16, 2017 15:09
-
-
Save rahularyan/a44a989bb83af1c82c18c716993fbf55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filter AnsPress question permastruct. | |
* | |
* @param array $structure Question rules. | |
* @return array | |
*/ | |
function my_ap_question_perm_structure( $structure ) { | |
add_rewrite_tag( '%question_category%', '([^/]+)' ); | |
$question_slug = ap_get_page_slug( 'question' ); | |
$structure['rule'] = ap_base_page_slug() . '' . $question_slug . '/%question_category%/%question%'; | |
return $structure; | |
} | |
add_filter( 'ap_question_perm_structure', 'my_ap_question_perm_structure' ); | |
/** | |
* Filter question link and replace %question_category% with first category slug. | |
* | |
* @param string $link | |
* @param WP_Post $post | |
* @return void | |
*/ | |
function my_ap_question_post_type_link( $link, $post ) { | |
$cat = get_the_terms( $post->ID, 'question_category' )[0]; | |
$link = str_replace( '%question_category%', $cat->slug, $link ); | |
return $link; | |
} | |
add_filter( 'ap_question_post_type_link', 'my_ap_question_post_type_link', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment