• First post type :

    add_action( 'init', 'create_pressrelease' );
    
    function create_pressrelease() {
    
    register_post_type( 'pressreleases',
        array(
                'labels' => array(
                        'name' => __( 'Press Releases' ),
                        'singular_name' => __( 'Press Release' )
                ),
        'has_archive' => true,
        'show_in_menu' => 'edit.php?post_type=storefronts',
            'public' => true,
        'map_meta_cap'        => true,
        'menu_position' => 4,
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions' ),
        'taxonomies' => array( 'post_tag' ),
        'menu_icon' => 'dashicons-edit',
        'has_archive' => 'pressreleases',
        'with_front' => false,
        'rewrite' => array(
                    'slug' => 'suppliers/%supplier_name%/pressreleases',
                )
        )
        );
    }

    Second post type :

    add_action( 'init', 'create_whitepaper' );
    function create_whitepaper() {
    register_post_type( 'whitepapers',
        array(
                'labels' => array(
                        'name' => __( 'White Papers' ),
                        'singular_name' => __( 'White Paper' )
                ),
        'has_archive' => true,
        'show_in_menu' => 'edit.php?post_type=storefronts',
        'public' => true,
        'map_meta_cap'        => true,
        'menu_position' => 4,
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions' ),
        'taxonomies' => array( 'post_tag' ),
                'menu_icon' => 'dashicons-edit',
        'has_archive' => 'whitepapers',
        'rewrite' => array(
                    'slug' => 'suppliers/%supplier_name%/whitepapers',
                )
        )
        );
    }

    I have created above post types two , I am able to get first post type correct pages and coming to 2nd post type, I am getting URL but the loads homepage content, why it is happening is there anything that i m missing to include in this both codes.suggest me i am trying since two days I have tired various methods like add_rewrite, perma_structure, need some solution on this

Viewing 2 replies - 1 through 2 (of 2 total)
  • Your code has a few errors in it.

    Try following good code practice as well

    function book_setup_post_type() {
        $args = array(
            'public'    => true,
            'label'     => __( 'Books', 'textdomain' ),
            'menu_icon' => 'dashicons-book',
        );
        register_post_type( 'book', $args );
    }
    add_action( 'init', 'book_setup_post_type' );

    And review this page for all things post registering.

    Moderator bcworkz

    (@bcworkz)

    Try visiting the Permalinks Setting screen. Doing so flushes the old rewrite rules and recreates them using the currently registered post types. flush_rewrite_rules() does the same thing, but should not be called on every request as is what happens when you hook “init”. This function should only be called once when a theme or plugin is activated.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘wordpress register post type rewrite rule doesn’t work’ is closed to new replies.