Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to rewrite my permalinks using meta data from my post. The permalink rewrite works- but I'm getting the 404 issue when I try to view the post.

I've flushed by visiting the permalink settings page, and still no dice.

Could someone offer a clue as to why this wouldn't work?


function calendar_link_filter( $post_link, $id = 0, $leavename = FALSE ) {
    $post = get_post($id);
    if($post->post_type != 'super_duper') {
            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_action( 'init', 'create_my_post_types' );

function create_my_post_types() {
register_post_type( 'super_duper',
        'labels' => array(
            'name' => __( 'Super Dupers' ),
            'singular_name' => __( 'Super Duper' )
        'hierarchical' => false,
        'show_ui' => true, // UI in admin panel
        'publicly_queryable' => true,
        'rewrite' => true,
        'public' => true,
        'rewrite' => array('slug' => 'events8/%cal_year%/%cal_month%/%cal_day%'),

share|improve this question
I believe it has to do with adding rewrite tags... – Joe Nov 23 '10 at 20:27
Joe, can you leave a comment it Jan Fabry's answer was helpful? – hakre Feb 5 '11 at 17:25

1 Answer 1

Indeed, you need to add the rewrite tags. They indicate what can come in the place of your %cal_year% and similar tags:

add_rewrite_tag( '%cal_year%', '([0-9]{4})' );
add_rewrite_tag( '%cal_month%', '([0-9]{1,2})' );
add_rewrite_tag( '%cal_day%', '([0-9]{1,2})' );

This works, but I don't understand how: it seems to me something is missing to let WordPress know how it should get from 2010/12/31 to 2010-12-31 or however you saved your custom value. Maybe it just defaults back to the slug?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.