Custom post shows 404 after theme change

i have a custom post created using a plugin. But randomly say if i change the theme the post shows a 404. I tried flush_rewrite_rules() and resaving the permalink, theme change but still it shows 404.

add_action( ‘init’, ‘ggowl_custom_template_post’, 0 );

function ggowl_custom_template_post(){
$labels = array(
‘name’ => esc_html_x( ‘Templates’, ‘Post Type General Name’, ‘ggowl’ ),
‘singular_name’ => esc_html_x( ‘Template’, ‘Post Type Singular Name’, ‘ggowl’ ),
‘menu_name’ => esc_html__( ‘GGOwl Templates’, ‘ggowl’ ),
‘name_admin_bar’ => esc_html__( ‘Post Type’, ‘ggowl’ ),
‘archives’ => esc_html__( ‘Template Archives’, ‘ggowl’ ),
‘attributes’ => esc_html__( ‘Template Attributes’, ‘ggowl’ ),
‘parent_item_colon’ => esc_html__( ‘Parent Template :’, ‘ggowl’ ),
‘all_items’ => esc_html__( ‘All Template’, ‘ggowl’ ),
‘add_new_item’ => esc_html__( ‘Add New Template’, ‘ggowl’ ),
‘add_new’ => esc_html__( ‘Add New’, ‘ggowl’ ),
‘new_item’ => esc_html__( ‘New Template’, ‘ggowl’ ),
‘edit_item’ => esc_html__( ‘Edit Template’, ‘ggowl’ ),
‘update_item’ => esc_html__( ‘Update Template’, ‘ggowl’ ),
‘view_item’ => esc_html__( ‘View Template’, ‘ggowl’ ),
‘view_items’ => esc_html__( ‘View Template’, ‘ggowl’ ),
‘search_items’ => esc_html__( ‘Search Template’, ‘ggowl’ ),
‘not_found’ => esc_html__( ‘Not found’, ‘ggowl’ ),
‘not_found_in_trash’ => esc_html__( ‘Not found in Trash’, ‘ggowl’ ),
‘featured_image’ => esc_html__( ‘Featured Image’, ‘ggowl’ ),
‘set_featured_image’ => esc_html__( ‘Set featured image’, ‘ggowl’ ),
‘remove_featured_image’ => esc_html__( ‘Remove featured image’, ‘ggowl’ ),
‘use_featured_image’ => esc_html__( ‘Use as featured image’, ‘ggowl’ ),
‘insert_into_item’ => esc_html__( ‘Insert into Template’, ‘ggowl’ ),
‘uploaded_to_this_item’ => esc_html__( ‘Uploaded to this Template’, ‘ggowl’ ),
‘items_list’ => esc_html__( ‘Templates list’, ‘ggowl’ ),
‘items_list_navigation’ => esc_html__( ‘Templates list navigation’, ‘ggowl’ ),
‘filter_items_list’ => esc_html__( ‘Filter Templates list’, ‘ggowl’ ),
);
$args = array(
‘label’ => esc_html__( ‘Template’, ‘ggowl’ ),
‘description’ => esc_html__( ‘Create templates’, ‘ggowl’ ),
‘labels’ => $labels,
‘supports’ => array( ‘title’, ‘editor’, ‘revisions’,’comments’ ),
‘hierarchical’ => false,
‘public’ => false,
‘show_ui’ => true,
‘show_in_menu’ => false,
‘menu_position’ => 5,
‘menu_icon’ => ‘dashicons-clipboard’,
‘show_in_admin_bar’ => false,
‘show_in_nav_menus’ => false,
‘can_export’ => true,
‘has_archive’ => true,
‘exclude_from_search’ => true,
‘publicly_queryable’ => true,
‘capability_type’ => ‘page’,
);
register_post_type( ‘ggowl_template’, $args );
}

and this is how i have set the template for that custom post type

add_filter(‘single_template’, ‘ggowl_template_core’);

function ggowl_template_core($single)
{

global $post;
/* Checks for single template by post type */
if ($post->post_type == ‘ggowl_template’) {
if (file_exists(plugin_dir_path(GGOWL_PLUGIN_FILE) . ‘admin/templatereg/core-template/ggowl-template-core.php’)) {
return plugin_dir_path(GGOWL_PLUGIN_FILE) . ‘admin/templatereg/core-template/ggowl-template-core.php’;
}
}
return $single;
}

Read more here:: Custom post shows 404 after theme change

Leave a Reply

Your email address will not be published. Required fields are marked *