i have a custom post type and every single post it displays post date like 05 Jun 2019. i show this date with this code :

<a href="<?php echo get_day_link(get_post_time('Y'), get_post_time('m'), get_post_time('j'));  ?>" class="entry-date"><?php the_time('F j, Y') ?></a>

Problem is that when i click date to see posts published on the same date, i get 404 error because link generated like this "website.com/2019/05/29/". But if i manually enter this url "site.com/my-custom-post-type/2019/05/29/" i can get good result. after this problem i added this code to functions.php and flushed permalinks.

add_filter( 'getarchives_where', 'getarchives_where_filter', 10, 2 );
add_filter( 'generate_rewrite_rules', 'generate_my-custom-post-type_rewrite_rules' );

function getarchives_where_filter( $where, $args ) {

    if ( isset($args['post_type']) ) {      
        $where = "WHERE post_type = '$args[post_type]' AND post_status = 'publish'";

    return $where;

function generate_my-custom-post-type_rewrite_rules( $wp_rewrite ) {

    $event_rules = array(
        'my-custom-post-type/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$' => 'index.php?post_type=my-custom-post-type&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]',
        'my-custom-post-type/([0-9]{4})/([0-9]{1,2})/?$' => 'index.php?post_type=my-custom-post-type&year=$matches[1]&monthnum=$matches[2]',
        'my-custom-post-type/([0-9]{4})/?$' => 'index.php?post_type=my-custom-post-type&year=$matches[1]' 

    $wp_rewrite->rules = $event_rules + $wp_rewrite->rules;

function get_archives_my-custom-post-type_link( $link ) {

    return str_replace( get_site_url(), get_site_url() . '/my-custom-post-type', $link );


but it doesnt work yet. i still get the 404 error with the same url structure "website.com/2019/05/29/". anyone has idea?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.