• 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)
  • Hello! Thank you for this tip, it works great but I need something a little bit different, and definitely, my PHP knowledge are short: I tried to change things in your code but always get errors. In the slug, instead of “event” I would like to have “calendari” and keep the post name (instead of having id). Any help would be very appreciate!! Thank you in advance

    same here, I’ like to keep the post name.

    So far I’ve found this hack, I do not particularly like it as it changes core files, however it is the only way I’ve found that lets me change the permalink and keep the post name

    http://wordimpress.com/all-in-one-event-calendar-custom-permalink-slugs/

    Hope it helps

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.