• Hello,

    i created a Custom Post Type “publication”, and i can view the items under mysite.com/publication/. But i need to view this items under mysite.com/veroeffentlichungen/, so i use the rewrite-attribute in my Custom Post Type, but i get an 404 when i access mysite.com/veroeffentlichungen/. I have resaved the Permalink-Setting already.

    <?php
    // Register Custom Post Type
    function publication_post_type() {
    
    	$labels = array(
    			'name'                => _x( 'Ver?ffentlichungen', 'Post Type General Name', 'text_domain' ),
    			'singular_name'       => _x( 'Ver?ffentlichung', 'Post Type Singular Name', 'text_domain' ),
    			'menu_name'           => __( 'Ver?ffentlich.', 'text_domain' ),
    			'parent_item_colon'   => __( 'Parent Product:', 'text_domain' ),
    			'all_items'           => __( 'Alle Ver?ffentlichungen', 'text_domain' ),
    			'view_item'           => __( 'Ver?ffentlichungen ansehen', 'text_domain' ),
    			'add_new_item'        => __( 'Neue Ver?ffentlichung', 'text_domain' ),
    			'add_new'             => __( 'Ver?ffentlichung hinzufügen', 'text_domain' ),
    			'edit_item'           => __( 'Ver?ffentlichung bearbeiten', 'text_domain' ),
    			'update_item'         => __( 'Ver?ffentlichung aktualisieren', 'text_domain' ),
    			'search_items'        => __( 'Ver?ffentlichung suchen', 'text_domain' ),
    			'not_found'           => __( 'keine Ver?ffentlichung gefunden', 'text_domain' ),
    			'not_found_in_trash'  => __( 'keine Ver?ffentlichungen im Papierkorb gefunden', 'text_domain' ),
    	);
    	$rewrite = array(
    		'slug'                => 'veroeffentlichungen',
    		'with_front'          => false,
    		'pages'               => true,
    		'feeds'               => false,
    	);
    
    	$args = array(
    			'label'               => __( 'publication', 'text_domain' ),
    			'description'         => __( 'Ver?ffentlichungen', 'text_domain' ),
    			'labels'              => $labels,
    			'supports'            => array( 'title', ),
    			'taxonomies'          => array( 'category', 'post_tag' ),
    			'hierarchical'        => false,
    			'public'              => true,
    			'show_ui'             => true,
    			'show_in_menu'        => true,
    			'show_in_nav_menus'   => true,
    			'show_in_admin_bar'   => true,
    			'menu_position'       => 5,
    			'can_export'          => true,
    			'has_archive'         => true,
    			'exclude_from_search' => false,
    			'publicly_queryable'  => true,
    			'capability_type'     => 'post',
    	);
    	register_post_type( 'publication', $args );
    
    }
    
    // Hook into the 'init' action
    add_action( 'init', 'publication_post_type', 0 );

    What am i doing wrong?

    Thanks a lot.
    Andy

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi Andy, when you rewrite a CPT slug you need to flush the rewrite rules for them to take affect.

    Either add flush_rewrite_rules(); just under register_post_type( ‘publication’, $args ); and run it once (you only need it to run once) or manually flush them by switching your permalinks to something else and back to their correct settings.

    Thread Starter Andy Tschiersch

    (@tschan)

    Hi Christoph,

    thank you very much for this hint, but unfortunately it still does not work. I have also read this article (https://omfgitsnater.com/2012/06/using-flush_rewrite_rules-with-your-custom-post-types/) and tried a lot. I’m afraid I’ll have to rename the CPT, but I would like to know why this does not work.

    Thank you,
    Andy

    Thread Starter Andy Tschiersch

    (@tschan)

    omg, my fault, my fault, my fault…

    I have forgotten to ad the $rewrite-Array to the $args-Array:

    'rewrite' => $rewrite,'

    I’m so sorry.
    Andy

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Post Type with rewrite slug’ is closed to new replies.