This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Custom post permalink example with %post_id%

By: a guest on Nov 21st, 2012  |  syntax: PHP  |  size: 0.76 KB  |  views: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. add_action('init', 'tribe_events_rewrite');
  2. function tribe_events_rewrite() {
  3.     global $wp_rewrite;
  4.         $queryarg = 'post_type=tribe_events&p=';
  5.     $wp_rewrite->add_rewrite_tag('%tribe_events_id%', '([^/]+)',$queryarg);
  6.     $wp_rewrite->add_permastruct('tribe_events', '/event/%tribe_events_id%', false); }
  7.        
  8. add_filter('post_type_link', 'tribe_events_permalink', 1, 3);
  9. function tribe_events_permalink($post_link, $id = 0, $leavename) {
  10.     global $wp_rewrite;
  11.     $post = &get_post($id);
  12.     if ( is_wp_error( $post ) )
  13.         return $post;
  14.     $newlink = $wp_rewrite->get_extra_permastruct($post->post_type);
  15.     $newlink = str_replace('%'.$post->post_type.'_id%', $post->ID, $newlink);
  16.     $newlink = home_url(user_trailingslashit($newlink));
  17.     return $newlink;
  18. }
clone this paste RAW Paste Data