Every time you change rewrite rules, you need to rebuild the rewrite rules in the database. You can do that flush_rewrite_rules()
function, but don’t use it in every page load, you only need to do it once. In general, a very good hook to do it is the register_actionvation_hook()
of your plugin. You should rebuild the rewrite rules also when your plugin is deactivated in order to remove you custom rewrite rules:
register_activation_hook( __FILE__, function () {
cyb_register_vmgallery_post_type();
flush_rewrite_rules();
} );
register_deactivation_hook( __FILE__, function () {
flush_rewrite_rules();
} );
add_action( 'init', 'cyb_register_vmgallery_post_type' );
function cyb_register_vmgallery_post_type() {
$labels = array(
'name' => __('VmGallery', THEME_TEXT_DOMAIN),
'singular_name' => __('VmGallery', THEME_TEXT_DOMAIN),
'add_new' => __('Add New', THEME_TEXT_DOMAIN),
'add_new_item' => __('Add New Gallery', THEME_TEXT_DOMAIN),
'edit_item' => __('Edit Gallery', THEME_TEXT_DOMAIN),
'new_item' => __('New Gallery', THEME_TEXT_DOMAIN),
'all_items' => __('All Galleries', THEME_TEXT_DOMAIN),
'view_item' => __('View Gallery', THEME_TEXT_DOMAIN),
'search_items' => __('Search Gallery', THEME_TEXT_DOMAIN),
'not_found' => __('No galleries found', THEME_TEXT_DOMAIN),
'not_found_in_trash' => __('No galleries found in the Trash', THEME_TEXT_DOMAIN),
'parent_item_colon' => '',
'menu_name' => __('Gallery', THEME_TEXT_DOMAIN),
);
$supports = array('title', 'editor', 'thumbnail', 'excerpt', 'comments', 'custom-fields', 'post-formats', 'author', 'excerpt');
$args = array(
'labels' => $labels,
'description' => 'Galleries specific information',
'public' => true,
'menu_position' => 6,
'menu_icon' => 'dashicons-format-image',
'supports' => $supports,
'taxonomies' => array('gallery_categories', 'post_tag'),
'has_archive' => 'ggg'
/*'rewrite' => array(
'slug' => $slug,
'with_front' => false
),*/
);
register_post_type('vmgallery', $args);
}