1

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

<?php
    function create_posttype() {
        register_post_type( 'medya',
            array(
                'labels' => array(
                    'name' => __( 'نگارخانه' ),
                    'singular_name' => __( 'اثر' )),
                'supports' => array(
                  'title',
                  'editor',
                  'thumbnail',
                  'revisions',
                  'comments'),
                '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 () {
        register_taxonomy(
            'medya-cats',
            'medya',
            array(
                '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:

mysite.com/gallery/animations/[the-name-of-animation]

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

UPDATE:

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, privacy policy and cookie policy

Browse other questions tagged or ask your own question.