Forums

All-in-One Event Calendar
Changing permalink, using postid instead of postname sample code (1 post)

  1. wpmubp
    Member
    Posted 6 months ago #

    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/

Reply

You must log in to post.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 6 months ago by wpmubp
  • This topic is not a support question
  • WordPress version: 3.4.2

Tags

No tags yet.