• Resolved anik786

    (@anik786)


    Hi.

    For some reason the custom post types peramalinks is not working correctly.

    They are showing up like this:
    http://localhost/site-name/?course=maths

    when I want it like this:
    http://localhost/site-name/course/eyebrow-shaping-ebs

    I have used the following code in my THEME [NOT PLUGIN] functions file:

    function create_post_types() {
    	$labels = array(
    		'name'               => 'Courses',
    		'singular_name'      => 'Course',
                    ....more labels that are not relevent
    	);
    
    	$args = array(
    		'labels'             => $labels,
    		'public'             => true,
    		'publicly_queryable' => true,
    		'show_ui'            => true,
    		'show_in_menu'       => true,
    		'menu_icon'          => 'dashicons-book-alt',
    		'query_var'          => true,
    		'rewrite'            => array( 'slug' => 'course' ),
    		'capability_type'    => 'post',
    		'has_archive'        => true,
    		'hierarchical'       => false,
    		'menu_position'      => 5,
    		'supports'           => array( 'title' )
    	);
    
    	register_post_type( 'course', $args );
    }
    add_action( 'init', 'create_post_types' );

    I also used rewrite flush (although I think this is only needed when using custom posts within a plugin, not a theme- correct me if I’m wrong).

    function rewrite_flush() {
    	create_post_types();
    	flush_rewrite_rules();
    }
    register_activation_hook( __FILE__, 'rewrite_flush' );

    Please HELP!!!!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Custom Post Types Permalinks not working correctly’ is closed to new replies.