heavenbr / wordpress-custom-content-type-manager

Automatically exported from code.google.com/p/wordpress-custom-content-type-manager
0 stars 0 forks source link

Custom Post Type Template switching to archive.php after (any) plugin update #588

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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)

// 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

Original issue reported on code.google.com by and...@keithmcmillen.com on 8 May 2015 at 11:16

Attachments:

GoogleCodeExporter commented 8 years ago
https://github.com/craftsmancoding/custom-content-type-manager/issues/26

Original comment by ever...@fireproofsocks.com on 11 May 2015 at 5:49