• Hi,
    Thanks for making the awesome CCTM plugin, i’ve been using it for years and am excited for the upcoming licensed version of the plugin. I have a persistent issue that until recently i haven’t been able to pin down the cause of. Using the latest WP and CCTM.

    Issue: Everytime any plugins (possibly core as well) are updated, the selected page template for the Projects page gets set to the archives.php (as a temp fix, archive-project.php).
    Stupid Solution: uncheck ‘Enable Archives’, save, check ‘Enable Archives’, save. Works everytime.

    Custom Post Type : Project

    Enable Archives : checked
    Enable Categories : checked
    Permalink Action : Custom

    Using custom page template : page-projects.php (grid of Projects)

    3 functions added to functions.php to enable Custom Post Type Archives (like a normal blog, linked to in the sidebar)

    [ Moderator note: Code fixed, please wrap code in backticks or use the code button. ]

    // add Custom Post Types to archive pages
    add_filter( 'getarchives_where', 'getarchives_where_filter', 10, 2 );
    add_filter( 'generate_rewrite_rules', 'generate_projects_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_projects_rewrite_rules( $wp_rewrite ) {
      $project_rules = array(
        'projects/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$' => 'index.php?post_type=project&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]',
        'projects/([0-9]{4})/([0-9]{1,2})/?$' => 'index.php?post_type=project&year=$matches[1]&monthnum=$matches[2]',
        'projects/([0-9]{4})/?$' => 'index.php?post_type=project&year=$matches[1]'
      );
      $wp_rewrite->rules = $project_rules + $wp_rewrite->rules;
    }
    
    function get_archives_projects_link( $link ) {
      return str_replace( get_site_url(), get_site_url() . '/projects', $link );
    };

    Thanks for the help.
    Andrej

    https://www.ads-software.com/plugins/custom-content-type-manager/

Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom Post Type Template switching to archive.php after (any) plugin update’ is closed to new replies.