• Hi all,

    I got a custom post type and I created multiple categories for them.
    The problem is that I’m able to create category pages for each category but not an archive for all posts in my custom post type.

    I think it got something to do with the rewriting of the slug.
    Below I added the rewrite, because normally custom post types creates an url without the category in it:
    'rewrite' => array('slug' => 'recept/%category%','with_front' => false),

    Below the function:

    function wpa_course_post_link( $post_link, $id = 0 ){
        $post = get_post($id);
        if ( is_object( $post ) ){
            $terms = wp_get_object_terms( $post->ID, 'category' );
            if( $terms ){
                return str_replace( '%category%' , $terms[0]->slug , $post_link );
            } else {
            	return str_replace( '%category%' , "" );
            }
        }
        return $post_link;

    Now my custom post type is recept and I’m not able to create a archive page for it. It gives me a 404.

    Anybody got an idea what’s going wrong?

    Cheers

Viewing 1 replies (of 1 total)
  • Thread Starter Genuanceerd

    (@genuanceerd)

    Well, I know what’s going wrong.
    I just don’t know how to fix it.

    The archive is located at /recept/%category%/
    So I tried do a fix it but then nothing works.

    'rewrite'				=> array('slug' => 'recept/','with_front' => false),
    function wpa_course_post_link( $post_link, $id = 0 ){
        $post = get_post($id);
        if ( is_object( $post ) ){
            $terms = wp_get_object_terms( $post->ID, 'category' );
            if( $terms ){
                return str_replace( 'recept/' , 'recept/'.$terms[0]->slug , $post_link );
            }
        }
        return $post_link;

Viewing 1 replies (of 1 total)

The topic ‘[CPT] Archive & category pages’ is closed to new replies.