I have created a custom post type called "medya" with the codes below:

    function create_posttype() {
        register_post_type( 'medya',
                'labels' => array(
                    'name' => __( 'نگارخانه' ),
                    'singular_name' => __( 'اثر' )),
                'supports' => array(
                'public' => true,
                'has_archive' => true,
                'rewrite' => array('slug' => 'gallery', 'with_front' => false),
                'publicly_queryable' => true,
    add_action( 'init', 'create_posttype' );

    function add_tags_categories() {
        register_taxonomy_for_object_type('post_tag', 'medya');
    add_action('init', 'add_tags_categories');

    function build_taxonomies () {
                'hierarchical' => true,
                'label' => 'نوع ویدیو',
                'query_var' => true,
                'rewrite' => array( 'slug' => 'gallery', 'with_front' => false),

    add_action( 'init', 'build_taxonomies', 0 );

I have a category called "animations", so when I create a new post of "animations" category and "medya" cpt, the url will be like:


The problem is, when I visit the post itself, it returns 404; but archive pages like mysite.com/gallery/short-films are correct. I have tested them with taxonomy-medya-cats.php


I'm using "Custom Post Type Permalinks" plugin and url structure for "medya" cpt is: mysite.com/gallery/%medya-cats%/%postname%

The url structure for normal posts is: mysite.com/blog/%category%/%postname

I noticed when I remove the "blog" from the structure, the post shows correctly, but archives become invalid (404).

Which part is wrong and what should I do?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.