Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'post_type_link', array( $this, 'changeCustomPostTypeUrl' ), 1, 3 );
- add_action( 'init', array( $this, 'customPostTypeReWriteRules' ) );
- function changeCustomPostTypeUrl( $post_link, $id = 0 ) {
- $post = get_post( $id );
- if ( $post->post_type == 'chart' ) {
- if ( is_object( $post ) ) {
- $terms = wp_get_object_terms( $post->ID,
- array( 'chart_type' ) );
- if ( $terms ) {
- return str_replace( '%cat%',
- $terms[0]->slug,
- $post_link );
- }
- }
- }
- return $post_link;
- }
- function customPostTypeReWriteRules() {
- add_rewrite_rule( '^hitlister/(.*)/(.*)?$',
- 'index.php?post_type=chart&name=matches[2]',
- 'top' );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement