Changing permalink, using postid instead of postname sample code
-
I spent more than a few hours to find and get this working (wish I knew programming). This example code below lets you change the permalink from ai1ec_event to event, and also allows displaying
%post_id%
instead of%postname%
.Add this to your functions.php and don’t forget to click save on your WordPress permalink setting page (you don’t have to change anything).
add_action('init', 'ai1ec_event_rewrite'); function ai1ec_event_rewrite() { global $wp_rewrite; $queryarg = 'post_type=ai1ec_event&p='; $wp_rewrite->add_rewrite_tag('%ai1ec_event_id%', '([^/]+)',$queryarg); $wp_rewrite->add_permastruct('ai1ec_event', '/event/%ai1ec_event_id%', false); } add_filter('post_type_link', 'ai1ec_event_permalink', 1, 3); function ai1ec_event_permalink($post_link, $id = 0, $leavename) { global $wp_rewrite; $post = &get_post($id); if ( is_wp_error( $post ) ) return $post; $newlink = $wp_rewrite->get_extra_permastruct($post->post_type); $newlink = str_replace('%'.$post->post_type.'_id%', $post->ID, $newlink); $newlink = home_url(user_trailingslashit($newlink)); return $newlink; }
http://wordpress.org/extend/plugins/all-in-one-event-calendar/
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Changing permalink, using postid instead of postname sample code’ is closed to new replies.