WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Calendar For Custom Post Types
[resolved] Incorrect calendar link URLs (2 posts)

  1. serons
    Member
    Posted 2 years ago #

    I tried to adapt the code from this support thread in order to have the calendar links point to CPT slug URLs, but get strange results when I move the site from my local development environment to my live site.

    Locally I have the site at http://wp.dev/subdir/ and a calendar URLs are on the form http://wp.dev/subdir/journal/2012/06/7 which points to the CPT slug URL and is correct.

    When moved to the live server the WP installation resides in (the hypothetical domain) http://livesite.com/subdir and the site at http://livesite.com. (WordPress Address (URL) and Site Address (URL) respectively under General Settings). There the calendar entries point to http://livesite.com/subdir/journal/2012/06/7 but should point to http://livesite.com/journal/2012/06/7. I expect site_url() to return http://livesite.com but it seems to return http://livesite.com/subdir. I tried refreshing permalinks but it doesn't help.

    I also get strange concatenated URLs when I replace site_url() with a hardcoded string. I don't understand why I get this behaviour. Could you help?

    /**
     * Find the Custom Post Type and replace the calendar day link
     */
    function my_calendar_day_link( $url, $year, $month, $day ) {
    
    	$cpt = 'my_journal';
    
    	// Filter post types here
    	if ( !is_post_type_archive( $cpt ) ) return $url;
    
    	$slug = get_post_type_object($cpt)->rewrite['slug'];
    	return site_url() . "/" . $slug . "/" . $year . "/" . $month . "/" . $day;
    }
    
    add_filter( 'day_link', 'my_calendar_day_link', 10, 4 );
    
    /**
     * Find the Custom Post Type and replace the calendar month link
     */
    function my_calendar_month_link( $url, $year, $month ) {
    
    	$cpt = 'my_journal';
    
    	// Filter post types here
    	if ( !is_post_type_archive( $cpt ) ) return $url;
    
    	$slug = get_post_type_object($cpt)->rewrite['slug'];
    	return site_url() . "/" . $slug . "/" . $year . "/" . $month;
    }
    add_filter( 'month_link', 'my_calendar_month_link', 10, 3 );

    http://wordpress.org/extend/plugins/post-types-calendar/

  2. serons
    Member
    Posted 2 years ago #

    I was able to fix this by replacing site_url() with home_url().

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic