Title: Rewrite Permalink based on Metadata
Last modified: August 19, 2016

---

# Rewrite Permalink based on Metadata

 *  [zumajoe](https://wordpress.org/support/users/zumajoe/)
 * (@zumajoe)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/rewrite-permalink-based-on-metadata/)
 * Hi there,
 * Is it possible to rewrite the permalink for a basic post, similair to the way
   it has been done for a custom-post-type in the following code below?
 * I have event postings and do not wish for the permalink to show the post date,
   rather the actual event date.
 * I feel that custom post types are unnecessary for what I need- but would really
   like to be able to modify my permalinks based on custom meta…
 *     ```
       add_action( 'init', 'create_calendar_type' );
       function create_calendar_type() {
                 register_post_type( 'calendar',
                   array(
                     'labels' => array(
                       'name' => __( 'Events2' ),
                       'singular_name' => __( 'Event2' )
                     ),
                     'public' => true,
                     'rewrite' => array('slug' => 'events2/%cal_year%/%cal_month%/%cal_day%'),
                     'show_ui' => true,
                     'capability_type' => post,
   
                   )
       );
       }
   
       function calendar_link_filter( $post_link, $id = 0, $leavename = FALSE ) {
               $post = get_post($id);
               if($post->post_type != 'calendar') {
                       return $post_link;
               }
               $date = get_post_meta($post->ID,'event_start_date',true);
               $date = strtotime($date);
               $str = $post_link;
               $str = str_replace('%cal_year%',date("Y",$date),$str);
               $str = str_replace('%cal_month%',date("m",$date),$str);
               $str = str_replace('%cal_day%',date("d",$date),$str);
               return $str;
       }
       add_filter('post_type_link','calendar_link_filter',1,3);
       ```
   

The topic ‘Rewrite Permalink based on Metadata’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [zumajoe](https://wordpress.org/support/users/zumajoe/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/rewrite-permalink-based-on-metadata/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
